lib/queue: Actually remove all _QUEUE macros

This commit is contained in:
ZyX 2016-05-30 20:21:46 +03:00
parent 9ce921a516
commit cafd4a4d06

View File

@ -24,77 +24,71 @@ typedef struct _queue {
struct _queue *prev; struct _queue *prev;
} QUEUE; } QUEUE;
// Private macros.
#define _QUEUE_NEXT(q) ((q)->next)
#define _QUEUE_PREV(q) ((q)->prev)
#define _QUEUE_PREV_NEXT(q) (_QUEUE_NEXT(_QUEUE_PREV(q)))
#define _QUEUE_NEXT_PREV(q) (_QUEUE_PREV(_QUEUE_NEXT(q)))
// Public macros. // Public macros.
#define QUEUE_DATA(ptr, type, field) \ #define QUEUE_DATA(ptr, type, field) \
((type *)((char *)(ptr) - offsetof(type, field))) ((type *)((char *)(ptr) - offsetof(type, field)))
#define QUEUE_FOREACH(q, h) \ #define QUEUE_FOREACH(q, h) \
for ( /* NOLINT(readability/braces) */ \ for ( /* NOLINT(readability/braces) */ \
(q) = _QUEUE_NEXT(h); (q) != (h); (q) = _QUEUE_NEXT(q)) (q) = (h)->next; (q) != (h); (q) = (q)->next)
// ffi.cdef is unable to swallow `bool` in place of `int` here. // ffi.cdef is unable to swallow `bool` in place of `int` here.
static inline int QUEUE_EMPTY(const QUEUE *const q) static inline int QUEUE_EMPTY(const QUEUE *const q)
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return q == _QUEUE_NEXT(q); return q == q->next;
} }
#define QUEUE_HEAD _QUEUE_NEXT #define QUEUE_HEAD(q) (q)->next
static inline void QUEUE_INIT(QUEUE *const q) FUNC_ATTR_ALWAYS_INLINE static inline void QUEUE_INIT(QUEUE *const q) FUNC_ATTR_ALWAYS_INLINE
{ {
_QUEUE_NEXT(q) = q; q->next = q;
_QUEUE_PREV(q) = q; q->prev = q;
} }
static inline void QUEUE_ADD(QUEUE *const h, QUEUE *const n) static inline void QUEUE_ADD(QUEUE *const h, QUEUE *const n)
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_ALWAYS_INLINE
{ {
_QUEUE_PREV_NEXT(h) = _QUEUE_NEXT(n); h->prev->next = n->next;
_QUEUE_NEXT_PREV(n) = _QUEUE_PREV(h); n->next->prev = h->prev;
_QUEUE_PREV(h) = _QUEUE_PREV(n); h->prev = n->prev;
_QUEUE_PREV_NEXT(h) = h; h->prev->next = h;
} }
static inline void QUEUE_SPLIT(QUEUE *const h, QUEUE *const q, QUEUE *const n) static inline void QUEUE_SPLIT(QUEUE *const h, QUEUE *const q, QUEUE *const n)
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_ALWAYS_INLINE
{ {
_QUEUE_PREV(n) = _QUEUE_PREV(h); n->prev = h->prev;
_QUEUE_PREV_NEXT(n) = n; n->prev->next = n;
_QUEUE_NEXT(n) = q; n->next = q;
_QUEUE_PREV(h) = _QUEUE_PREV(q); h->prev = q->prev;
_QUEUE_PREV_NEXT(h) = h; h->prev->next = h;
_QUEUE_PREV(q) = n; q->prev = n;
} }
static inline void QUEUE_INSERT_HEAD(QUEUE *const h, QUEUE *const q) static inline void QUEUE_INSERT_HEAD(QUEUE *const h, QUEUE *const q)
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_ALWAYS_INLINE
{ {
_QUEUE_NEXT(q) = _QUEUE_NEXT(h); q->next = h->next;
_QUEUE_PREV(q) = h; q->prev = h;
_QUEUE_NEXT_PREV(q) = q; q->next->prev = q;
_QUEUE_NEXT(h) = q; h->next = q;
} }
static inline void QUEUE_INSERT_TAIL(QUEUE *const h, QUEUE *const q) static inline void QUEUE_INSERT_TAIL(QUEUE *const h, QUEUE *const q)
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_ALWAYS_INLINE
{ {
_QUEUE_NEXT(q) = h; q->next = h;
_QUEUE_PREV(q) = _QUEUE_PREV(h); q->prev = h->prev;
_QUEUE_PREV_NEXT(q) = q; q->prev->next = q;
_QUEUE_PREV(h) = q; h->prev = q;
} }
static inline void QUEUE_REMOVE(QUEUE *const q) FUNC_ATTR_ALWAYS_INLINE static inline void QUEUE_REMOVE(QUEUE *const q) FUNC_ATTR_ALWAYS_INLINE
{ {
_QUEUE_PREV_NEXT(q) = _QUEUE_NEXT(q); q->prev->next = q->next;
_QUEUE_NEXT_PREV(q) = _QUEUE_PREV(q); q->next->prev = q->prev;
} }
#endif // NVIM_LIB_QUEUE_H #endif // NVIM_LIB_QUEUE_H