mirror of
https://github.com/neovim/neovim.git
synced 2026-01-18 02:59:25 +10:00
* refactor: general good option changes sp_deref = remove sp_not = remove sp_inv = remove sp_inside_paren_cast = remove mod_remove_duplicate_include = true sp_after_semi = add sp_after_semi_for = force sp_sizeof_paren = remove nl_return_expr = remove nl_else_brace = remove nl_else_if = remove * refactor: mod_remove_extra_semicolon = true * refactor: nl_max = 3 * refactor: sp_bool = force * refactor: sp_compare = force * refactor: sp_inside_paren = remove * refactor: sp_paren_paren = remove * refactor: sp_inside_sparen = remove * refactor: sp_before_sparen = force * refactor: sp_sign = remove * refactor: sp_addr = remove * refactor: sp_member = remove * refactor: nl_struct_brace = remove * refactor: nl_before_if_closing_paren = remove * refactor: nl_fdef_brace = force * refactor: sp_paren_comma = force * refactor: mod_full_brace_do = add
97 lines
2.6 KiB
C
97 lines
2.6 KiB
C
// Queue implemented by circularly-linked list.
|
|
//
|
|
// Adapted from libuv. Simpler and more efficient than klist.h for implementing
|
|
// queues that support arbitrary insertion/removal.
|
|
//
|
|
// Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl>
|
|
//
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// copyright notice and this permission notice appear in all copies.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
#ifndef NVIM_LIB_QUEUE_H
|
|
#define NVIM_LIB_QUEUE_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "nvim/func_attr.h"
|
|
|
|
typedef struct _queue {
|
|
struct _queue *next;
|
|
struct _queue *prev;
|
|
} QUEUE;
|
|
|
|
// Public macros.
|
|
#define QUEUE_DATA(ptr, type, field) \
|
|
((type *)((char *)(ptr) - offsetof(type, field)))
|
|
|
|
// Important note: the node currently being processed can be safely deleted.
|
|
// otherwise, mutating the list while QUEUE_FOREACH is iterating over its
|
|
// elements results in undefined behavior.
|
|
#define QUEUE_FOREACH(q, h, code) \
|
|
(q) = (h)->next; \
|
|
while ((q) != (h)) { \
|
|
QUEUE *next = q->next; \
|
|
code \
|
|
(q) = next; \
|
|
}
|
|
|
|
|
|
// ffi.cdef is unable to swallow `bool` in place of `int` here.
|
|
static inline int QUEUE_EMPTY(const QUEUE *const q)
|
|
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
|
{
|
|
return q == q->next;
|
|
}
|
|
|
|
#define QUEUE_HEAD(q) (q)->next
|
|
|
|
static inline void QUEUE_INIT(QUEUE *const q) FUNC_ATTR_ALWAYS_INLINE
|
|
{
|
|
q->next = q;
|
|
q->prev = q;
|
|
}
|
|
|
|
static inline void QUEUE_ADD(QUEUE *const h, QUEUE *const n)
|
|
FUNC_ATTR_ALWAYS_INLINE
|
|
{
|
|
h->prev->next = n->next;
|
|
n->next->prev = h->prev;
|
|
h->prev = n->prev;
|
|
h->prev->next = h;
|
|
}
|
|
|
|
static inline void QUEUE_INSERT_HEAD(QUEUE *const h, QUEUE *const q)
|
|
FUNC_ATTR_ALWAYS_INLINE
|
|
{
|
|
q->next = h->next;
|
|
q->prev = h;
|
|
q->next->prev = q;
|
|
h->next = q;
|
|
}
|
|
|
|
static inline void QUEUE_INSERT_TAIL(QUEUE *const h, QUEUE *const q)
|
|
FUNC_ATTR_ALWAYS_INLINE
|
|
{
|
|
q->next = h;
|
|
q->prev = h->prev;
|
|
q->prev->next = q;
|
|
h->prev = q;
|
|
}
|
|
|
|
static inline void QUEUE_REMOVE(QUEUE *const q) FUNC_ATTR_ALWAYS_INLINE
|
|
{
|
|
q->prev->next = q->next;
|
|
q->next->prev = q->prev;
|
|
}
|
|
|
|
#endif // NVIM_LIB_QUEUE_H
|