[util, formatting] changed list api to snakecase for consistency with the rest of the codebase
This commit is contained in:
parent
bfc19665ce
commit
3682605f97
|
@ -111,7 +111,7 @@ void debug_print_styles(ui_box* box, int indent)
|
|||
debug_print_size(box, UI_AXIS_X, indent);
|
||||
debug_print_size(box, UI_AXIS_Y, indent);
|
||||
|
||||
if(!ListEmpty(&box->beforeRules))
|
||||
if(!list_empty(&box->beforeRules))
|
||||
{
|
||||
debug_print_indent(indent);
|
||||
printf("before rules:\n");
|
||||
|
@ -122,7 +122,7 @@ void debug_print_styles(ui_box* box, int indent)
|
|||
}
|
||||
}
|
||||
|
||||
if(!ListEmpty(&box->afterRules))
|
||||
if(!list_empty(&box->afterRules))
|
||||
{
|
||||
debug_print_indent(indent);
|
||||
printf("after rules:\n");
|
||||
|
@ -133,7 +133,7 @@ void debug_print_styles(ui_box* box, int indent)
|
|||
}
|
||||
}
|
||||
|
||||
if(!ListEmpty(&box->children))
|
||||
if(!list_empty(&box->children))
|
||||
{
|
||||
debug_print_indent(indent);
|
||||
printf("children:\n");
|
||||
|
|
|
@ -241,7 +241,7 @@ u64 mg_handle_alloc(mg_handle_kind kind, void* data)
|
|||
}
|
||||
mem_arena* arena = &__mgData.handleArena;
|
||||
|
||||
mg_handle_slot* slot = ListPopEntry(&__mgData.handleFreeList, mg_handle_slot, freeListElt);
|
||||
mg_handle_slot* slot = list_pop_entry(&__mgData.handleFreeList, mg_handle_slot, freeListElt);
|
||||
if(!slot)
|
||||
{
|
||||
slot = mem_arena_alloc_type(arena, mg_handle_slot);
|
||||
|
@ -272,7 +272,7 @@ void mg_handle_recycle(u64 h)
|
|||
{
|
||||
DEBUG_ASSERT(slot->generation != UINT32_MAX, "surface slot generation wrap around\n");
|
||||
slot->generation++;
|
||||
ListPush(&__mgData.handleFreeList, &slot->freeListElt);
|
||||
list_push(&__mgData.handleFreeList, &slot->freeListElt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2248,7 +2248,7 @@ mg_font mg_font_create_from_memory(u32 size, byte* buffer, u32 rangeCount, unico
|
|||
}
|
||||
mg_font fontHandle = mg_font_nil();
|
||||
|
||||
mg_font_data* font = ListPopEntry(&__mgData.fontFreeList, mg_font_data, freeListElt);
|
||||
mg_font_data* font = list_pop_entry(&__mgData.fontFreeList, mg_font_data, freeListElt);
|
||||
if(!font)
|
||||
{
|
||||
font = mem_arena_alloc_type(&__mgData.resourceArena, mg_font_data);
|
||||
|
@ -2428,7 +2428,7 @@ void mg_font_destroy(mg_font fontHandle)
|
|||
free(fontData->glyphs);
|
||||
free(fontData->outlines);
|
||||
|
||||
ListPush(&__mgData.fontFreeList, &fontData->freeListElt);
|
||||
list_push(&__mgData.fontFreeList, &fontData->freeListElt);
|
||||
mg_handle_recycle(fontHandle.h);
|
||||
}
|
||||
}
|
||||
|
@ -2724,7 +2724,7 @@ mg_canvas mg_canvas_create(mg_surface surface)
|
|||
|
||||
if(backend)
|
||||
{
|
||||
mg_canvas_data* canvas = ListPopEntry(&__mgData.canvasFreeList, mg_canvas_data, freeListElt);
|
||||
mg_canvas_data* canvas = list_pop_entry(&__mgData.canvasFreeList, mg_canvas_data, freeListElt);
|
||||
if(!canvas)
|
||||
{
|
||||
canvas = mem_arena_alloc_type(&__mgData.resourceArena, mg_canvas_data);
|
||||
|
@ -2766,7 +2766,7 @@ void mg_canvas_destroy(mg_canvas handle)
|
|||
{
|
||||
canvas->backend->destroy(canvas->backend);
|
||||
}
|
||||
ListPush(&__mgData.canvasFreeList, &canvas->freeListElt);
|
||||
list_push(&__mgData.canvasFreeList, &canvas->freeListElt);
|
||||
mg_handle_recycle(handle.h);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ mp_app __mpApp = {0};
|
|||
|
||||
void mp_init_window_handles()
|
||||
{
|
||||
ListInit(&__mpApp.windowFreeList);
|
||||
list_init(&__mpApp.windowFreeList);
|
||||
for(int i=0; i<MP_APP_MAX_WINDOWS; i++)
|
||||
{
|
||||
__mpApp.windowPool[i].generation = 1;
|
||||
ListAppend(&__mpApp.windowFreeList, &__mpApp.windowPool[i].freeListElt);
|
||||
list_append(&__mpApp.windowFreeList, &__mpApp.windowPool[i].freeListElt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ mp_window mp_window_null_handle()
|
|||
|
||||
mp_window_data* mp_window_alloc()
|
||||
{
|
||||
return(ListPopEntry(&__mpApp.windowFreeList, mp_window_data, freeListElt));
|
||||
return(list_pop_entry(&__mpApp.windowFreeList, mp_window_data, freeListElt));
|
||||
}
|
||||
|
||||
mp_window_data* mp_window_ptr_from_handle(mp_window handle)
|
||||
|
@ -75,7 +75,7 @@ mp_window mp_window_handle_from_ptr(mp_window_data* window)
|
|||
void mp_window_recycle_ptr(mp_window_data* window)
|
||||
{
|
||||
window->generation++;
|
||||
ListPush(&__mpApp.windowFreeList, &window->freeListElt);
|
||||
list_push(&__mpApp.windowFreeList, &window->freeListElt);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
|
40
src/ui.c
40
src/ui.c
|
@ -219,7 +219,7 @@ void ui_tag_box_str8(ui_box* box, str8 string)
|
|||
ui_context* ui = ui_get_context();
|
||||
ui_tag_elt* elt = mem_arena_alloc_type(&ui->frameArena, ui_tag_elt);
|
||||
elt->tag = ui_tag_make_str8(string);
|
||||
ListAppend(&box->tags, &elt->listElt);
|
||||
list_append(&box->tags, &elt->listElt);
|
||||
}
|
||||
|
||||
void ui_tag_next_str8(str8 string)
|
||||
|
@ -227,7 +227,7 @@ void ui_tag_next_str8(str8 string)
|
|||
ui_context* ui = ui_get_context();
|
||||
ui_tag_elt* elt = mem_arena_alloc_type(&ui->frameArena, ui_tag_elt);
|
||||
elt->tag = ui_tag_make_str8(string);
|
||||
ListAppend(&ui->nextBoxTags, &elt->listElt);
|
||||
list_append(&ui->nextBoxTags, &elt->listElt);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -273,7 +273,7 @@ bool ui_key_equal(ui_key a, ui_key b)
|
|||
void ui_box_cache(ui_context* ui, ui_box* box)
|
||||
{
|
||||
u64 index = box->key.hash & (UI_BOX_MAP_BUCKET_COUNT-1);
|
||||
ListAppend(&(ui->boxMap[index]), &box->bucketElt);
|
||||
list_append(&(ui->boxMap[index]), &box->bucketElt);
|
||||
}
|
||||
|
||||
ui_box* ui_box_lookup_key(ui_key key)
|
||||
|
@ -305,7 +305,7 @@ void ui_pattern_push(mem_arena* arena, ui_pattern* pattern, ui_selector selector
|
|||
{
|
||||
ui_selector* copy = mem_arena_alloc_type(arena, ui_selector);
|
||||
*copy = selector;
|
||||
ListAppend(&pattern->l, ©->listElt);
|
||||
list_append(&pattern->l, ©->listElt);
|
||||
}
|
||||
|
||||
ui_pattern ui_pattern_all(void)
|
||||
|
@ -335,7 +335,7 @@ void ui_style_match_before(ui_pattern pattern, ui_style* style, ui_style_mask ma
|
|||
rule->style = mem_arena_alloc_type(&ui->frameArena, ui_style);
|
||||
*rule->style = *style;
|
||||
|
||||
ListAppend(&ui->nextBoxBeforeRules, &rule->boxElt);
|
||||
list_append(&ui->nextBoxBeforeRules, &rule->boxElt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,7 +350,7 @@ void ui_style_match_after(ui_pattern pattern, ui_style* style, ui_style_mask mas
|
|||
rule->style = mem_arena_alloc_type(&ui->frameArena, ui_style);
|
||||
*rule->style = *style;
|
||||
|
||||
ListAppend(&ui->nextBoxAfterRules, &rule->boxElt);
|
||||
list_append(&ui->nextBoxAfterRules, &rule->boxElt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,11 +431,11 @@ ui_box* ui_box_make_str8(str8 string, ui_flags flags)
|
|||
//NOTE: setup hierarchy
|
||||
if(box->frameCounter != ui->frameCounter)
|
||||
{
|
||||
ListInit(&box->children);
|
||||
list_init(&box->children);
|
||||
box->parent = ui_box_top();
|
||||
if(box->parent)
|
||||
{
|
||||
ListAppend(&box->parent->children, &box->listElt);
|
||||
list_append(&box->parent->children, &box->listElt);
|
||||
box->parentClosed = box->parent->closed || box->parent->parentClosed;
|
||||
}
|
||||
}
|
||||
|
@ -867,14 +867,14 @@ bool ui_style_selector_match(ui_box* box, ui_style_rule* rule, ui_selector* sele
|
|||
|
||||
void ui_style_rule_match(ui_context* ui, ui_box* box, ui_style_rule* rule, list_info* buildList, list_info* tmpList)
|
||||
{
|
||||
ui_selector* selector = ListFirstEntry(&rule->pattern.l, ui_selector, listElt);
|
||||
ui_selector* selector = list_first_entry(&rule->pattern.l, ui_selector, listElt);
|
||||
bool match = ui_style_selector_match(box, rule, selector);
|
||||
|
||||
selector = ListNextEntry(&rule->pattern.l, selector, ui_selector, listElt);
|
||||
selector = list_next_entry(&rule->pattern.l, selector, ui_selector, listElt);
|
||||
while(match && selector && selector->op == UI_SEL_AND)
|
||||
{
|
||||
match = match && ui_style_selector_match(box, rule, selector);
|
||||
selector = ListNextEntry(&rule->pattern.l, selector, ui_selector, listElt);
|
||||
selector = list_next_entry(&rule->pattern.l, selector, ui_selector, listElt);
|
||||
}
|
||||
|
||||
if(match)
|
||||
|
@ -891,8 +891,8 @@ void ui_style_rule_match(ui_context* ui, ui_box* box, ui_style_rule* rule, list_
|
|||
derived->style = rule->style;
|
||||
derived->pattern.l = (list_info){&selector->listElt, rule->pattern.l.last};
|
||||
|
||||
ListAppend(buildList, &derived->buildElt);
|
||||
ListAppend(tmpList, &derived->tmpElt);
|
||||
list_append(buildList, &derived->buildElt);
|
||||
list_append(tmpList, &derived->tmpElt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -915,8 +915,8 @@ void ui_styling_prepass(ui_context* ui, ui_box* box, list_info* before, list_inf
|
|||
}
|
||||
for_each_in_list(&box->beforeRules, rule, ui_style_rule, boxElt)
|
||||
{
|
||||
ListAppend(before, &rule->buildElt);
|
||||
ListAppend(&tmpBefore, &rule->tmpElt);
|
||||
list_append(before, &rule->buildElt);
|
||||
list_append(&tmpBefore, &rule->tmpElt);
|
||||
ui_style_rule_match(ui, box, rule, before, &tmpBefore);
|
||||
}
|
||||
|
||||
|
@ -927,8 +927,8 @@ void ui_styling_prepass(ui_context* ui, ui_box* box, list_info* before, list_inf
|
|||
}
|
||||
for_each_in_list(&box->afterRules, rule, ui_style_rule, boxElt)
|
||||
{
|
||||
ListAppend(after, &rule->buildElt);
|
||||
ListAppend(&tmpAfter, &rule->tmpElt);
|
||||
list_append(after, &rule->buildElt);
|
||||
list_append(&tmpAfter, &rule->tmpElt);
|
||||
ui_style_rule_match(ui, box, rule, after, &tmpAfter);
|
||||
}
|
||||
|
||||
|
@ -976,11 +976,11 @@ void ui_styling_prepass(ui_context* ui, ui_box* box, list_info* before, list_inf
|
|||
//NOTE: remove temporary rules
|
||||
for_each_in_list(&tmpBefore, rule, ui_style_rule, tmpElt)
|
||||
{
|
||||
ListRemove(before, &rule->buildElt);
|
||||
list_remove(before, &rule->buildElt);
|
||||
}
|
||||
for_each_in_list(&tmpAfter, rule, ui_style_rule, tmpElt)
|
||||
{
|
||||
ListRemove(after, &rule->buildElt);
|
||||
list_remove(after, &rule->buildElt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1362,7 +1362,7 @@ void ui_end_frame(void)
|
|||
{
|
||||
if(box->frameCounter < ui->frameCounter)
|
||||
{
|
||||
ListRemove(&ui->boxMap[i], &box->bucketElt);
|
||||
list_remove(&ui->boxMap[i], &box->bucketElt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
178
src/util/lists.h
178
src/util/lists.h
|
@ -36,45 +36,45 @@ extern "C" {
|
|||
// Intrusive linked lists
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
#define ListEntry(ptr, type, member) \
|
||||
#define list_entry(ptr, type, member) \
|
||||
CONTAINER_OF(ptr, type, member)
|
||||
|
||||
#define ListNext(elt) (elt)->next
|
||||
#define ListPrev(elt) (elt)->prev
|
||||
#define list_next(elt) (elt)->next
|
||||
#define list_prev(elt) (elt)->prev
|
||||
|
||||
#define ListNextEntry(list, elt, type, member) \
|
||||
((elt->member.next != ListEnd(list)) ? ListEntry(elt->member.next, type, member) : 0)
|
||||
#define list_next_entry(list, elt, type, member) \
|
||||
((elt->member.next != list_end(list)) ? list_entry(elt->member.next, type, member) : 0)
|
||||
|
||||
#define ListPrevEntry(list, elt, type, member) \
|
||||
((elt->member.prev != ListEnd(list)) ? ListEntry(elt->member.prev, type, member) : 0)
|
||||
#define list_prev_entry(list, elt, type, member) \
|
||||
((elt->member.prev != list_end(list)) ? list_entry(elt->member.prev, type, member) : 0)
|
||||
|
||||
#define ListCheckedEntry(list, type, member) \
|
||||
(((list) != 0) ? ListEntry(list, type, member) : 0)
|
||||
#define list_checked_entry(list, type, member) \
|
||||
(((list) != 0) ? list_entry(list, type, member) : 0)
|
||||
|
||||
#define ListFirstEntry(list, type, member) \
|
||||
(ListCheckedEntry(ListBegin(list), type, member))
|
||||
#define list_first_entry(list, type, member) \
|
||||
(list_checked_entry(list_begin(list), type, member))
|
||||
|
||||
#define ListLastEntry(list, type, member) \
|
||||
(ListCheckedEntry(ListLast(list), type, member))
|
||||
#define list_last_entry(list, type, member) \
|
||||
(list_checked_entry(list_last(list), type, member))
|
||||
|
||||
#define for_each_in_list(list, elt, type, member) \
|
||||
for(type* elt = ListCheckedEntry(ListBegin(list), type, member); \
|
||||
for(type* elt = list_checked_entry(list_begin(list), type, member); \
|
||||
elt != 0; \
|
||||
elt = ListCheckedEntry(elt->member.next, type, member)) \
|
||||
elt = list_checked_entry(elt->member.next, type, member)) \
|
||||
|
||||
#define for_each_in_list_reverse(list, elt, type, member) \
|
||||
for(type* elt = ListCheckedEntry(ListLast(list), type, member); \
|
||||
for(type* elt = list_checked_entry(list_last(list), type, member); \
|
||||
elt != 0; \
|
||||
elt = ListCheckedEntry(elt->member.prev, type, member)) \
|
||||
elt = list_checked_entry(elt->member.prev, type, member)) \
|
||||
|
||||
#define for_each_in_list_safe(list, elt, type, member) \
|
||||
for(type* elt = ListCheckedEntry(ListBegin(list), type, member), \
|
||||
*__tmp = elt ? ListCheckedEntry(elt->member.next, type, member) : 0 ; \
|
||||
for(type* elt = list_checked_entry(list_begin(list), type, member), \
|
||||
*__tmp = elt ? list_checked_entry(elt->member.next, type, member) : 0 ; \
|
||||
elt != 0; \
|
||||
elt = __tmp, \
|
||||
__tmp = elt ? ListCheckedEntry(elt->member.next, type, member) : 0) \
|
||||
__tmp = elt ? list_checked_entry(elt->member.next, type, member) : 0) \
|
||||
|
||||
#define ListPopEntry(list, type, member) (ListEmpty(list) ? 0 : ListEntry(ListPop(list), type, member))
|
||||
#define list_pop_entry(list, type, member) (list_empty(list) ? 0 : list_entry(list_pop(list), type, member))
|
||||
|
||||
typedef struct list_elt list_elt;
|
||||
struct list_elt
|
||||
|
@ -89,26 +89,26 @@ typedef struct list_info
|
|||
list_elt* last;
|
||||
} list_info;
|
||||
|
||||
static inline void ListInit(list_info* list)
|
||||
static inline void list_init(list_info* list)
|
||||
{
|
||||
list->first = list->last = 0;
|
||||
}
|
||||
|
||||
static inline list_elt* ListBegin(list_info* list)
|
||||
static inline list_elt* list_begin(list_info* list)
|
||||
{
|
||||
return(list->first);
|
||||
}
|
||||
static inline list_elt* ListEnd(list_info* list)
|
||||
static inline list_elt* list_end(list_info* list)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
static inline list_elt* ListLast(list_info* list)
|
||||
static inline list_elt* list_last(list_info* list)
|
||||
{
|
||||
return(list->last);
|
||||
}
|
||||
|
||||
static inline void ListInsert(list_info* list, list_elt* afterElt, list_elt* elt)
|
||||
static inline void list_insert(list_info* list, list_elt* afterElt, list_elt* elt)
|
||||
{
|
||||
elt->prev = afterElt;
|
||||
elt->next = afterElt->next;
|
||||
|
@ -122,10 +122,10 @@ static inline void ListInsert(list_info* list, list_elt* afterElt, list_elt* elt
|
|||
}
|
||||
afterElt->next = elt;
|
||||
|
||||
ASSERT(elt->next != elt, "ListInsert(): can't insert an element into itself");
|
||||
ASSERT(elt->next != elt, "list_insert(): can't insert an element into itself");
|
||||
}
|
||||
|
||||
static inline void ListInsertBefore(list_info* list, list_elt* beforeElt, list_elt* elt)
|
||||
static inline void list_insert_before(list_info* list, list_elt* beforeElt, list_elt* elt)
|
||||
{
|
||||
elt->next = beforeElt;
|
||||
elt->prev = beforeElt->prev;
|
||||
|
@ -140,10 +140,10 @@ static inline void ListInsertBefore(list_info* list, list_elt* beforeElt, list_e
|
|||
}
|
||||
beforeElt->prev = elt;
|
||||
|
||||
ASSERT(elt->next != elt, "ListInsertBefore(): can't insert an element into itself");
|
||||
ASSERT(elt->next != elt, "list_insert_before(): can't insert an element into itself");
|
||||
}
|
||||
|
||||
static inline void ListRemove(list_info* list, list_elt* elt)
|
||||
static inline void list_remove(list_info* list, list_elt* elt)
|
||||
{
|
||||
if(elt->prev)
|
||||
{
|
||||
|
@ -166,7 +166,7 @@ static inline void ListRemove(list_info* list, list_elt* elt)
|
|||
elt->prev = elt->next = 0;
|
||||
}
|
||||
|
||||
static inline void ListPush(list_info* list, list_elt* elt)
|
||||
static inline void list_push(list_info* list, list_elt* elt)
|
||||
{
|
||||
elt->next = list->first;
|
||||
elt->prev = 0;
|
||||
|
@ -181,12 +181,12 @@ static inline void ListPush(list_info* list, list_elt* elt)
|
|||
list->first = elt;
|
||||
}
|
||||
|
||||
static inline list_elt* ListPop(list_info* list)
|
||||
static inline list_elt* list_pop(list_info* list)
|
||||
{
|
||||
list_elt* elt = ListBegin(list);
|
||||
if(elt != ListEnd(list))
|
||||
list_elt* elt = list_begin(list);
|
||||
if(elt != list_end(list))
|
||||
{
|
||||
ListRemove(list, elt);
|
||||
list_remove(list, elt);
|
||||
return(elt);
|
||||
}
|
||||
else
|
||||
|
@ -195,7 +195,7 @@ static inline list_elt* ListPop(list_info* list)
|
|||
}
|
||||
}
|
||||
|
||||
static inline void ListPushBack(list_info* list, list_elt* elt)
|
||||
static inline void list_push_back(list_info* list, list_elt* elt)
|
||||
{
|
||||
elt->prev = list->last;
|
||||
elt->next = 0;
|
||||
|
@ -209,15 +209,15 @@ static inline void ListPushBack(list_info* list, list_elt* elt)
|
|||
}
|
||||
list->last = elt;
|
||||
}
|
||||
#define ListAppend(a, b) ListPushBack(a, b)
|
||||
#define list_append(a, b) list_push_back(a, b)
|
||||
|
||||
|
||||
static inline list_elt* ListPopBack(list_info* list)
|
||||
static inline list_elt* list_pop_back(list_info* list)
|
||||
{
|
||||
list_elt* elt = ListLast(list);
|
||||
if(elt != ListEnd(list))
|
||||
list_elt* elt = list_last(list);
|
||||
if(elt != list_end(list))
|
||||
{
|
||||
ListRemove(list, elt);
|
||||
list_remove(list, elt);
|
||||
return(elt);
|
||||
}
|
||||
else
|
||||
|
@ -226,7 +226,7 @@ static inline list_elt* ListPopBack(list_info* list)
|
|||
}
|
||||
}
|
||||
|
||||
static inline bool ListEmpty(list_info* list)
|
||||
static inline bool list_empty(list_info* list)
|
||||
{
|
||||
return(list->first == 0 || list->last == 0);
|
||||
}
|
||||
|
@ -236,70 +236,70 @@ static inline bool ListEmpty(list_info* list)
|
|||
// Circular Intrusive linked lists
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
#define CListEntry(ptr, type, member) ListEntry(ptr, type, member)
|
||||
#define CListNext(elt) ListNext(elt)
|
||||
#define CListPrev(elt) ListPrev(elt)
|
||||
#define clist_entry(ptr, type, member) list_entry(ptr, type, member)
|
||||
#define clist_next(elt) list_next(elt)
|
||||
#define clist_prev(elt) list_prev(elt)
|
||||
|
||||
#define CListNextEntry(head, elt, type, member) \
|
||||
((elt->member.next != CListEnd(head)) ? CListEntry(elt->member.next, type, member) : 0)
|
||||
#define clist_next_entry(head, elt, type, member) \
|
||||
((elt->member.next != clist_end(head)) ? clist_entry(elt->member.next, type, member) : 0)
|
||||
|
||||
#define CListPrevEntry(head, elt, type, member) \
|
||||
((elt->member.prev != CListEnd(head)) ? CListEntry(elt->member.prev, type, member) : 0)
|
||||
#define clist_prev_entry(head, elt, type, member) \
|
||||
((elt->member.prev != clist_end(head)) ? clist_entry(elt->member.prev, type, member) : 0)
|
||||
|
||||
#define CListCheckedEntry(head, info, type, member) \
|
||||
((info != CListEnd(head)) ? CListEntry(info, type, member) : 0)
|
||||
#define clist_checked_entry(head, info, type, member) \
|
||||
((info != clist_end(head)) ? clist_entry(info, type, member) : 0)
|
||||
|
||||
#define CListFirstEntry(head, type, member) \
|
||||
(CListCheckedEntry(head, CListBegin(head), type, member))
|
||||
#define clist_first_entry(head, type, member) \
|
||||
(clist_checked_entry(head, clist_begin(head), type, member))
|
||||
|
||||
#define CListLastEntry(head, type, member) \
|
||||
(CListCheckedEntry(head, CListLast(head), type, member))
|
||||
#define clist_last_entry(head, type, member) \
|
||||
(clist_checked_entry(head, clist_last(head), type, member))
|
||||
|
||||
#define for_each_in_clist(list, elt, type, member) \
|
||||
for(type* elt = CListEntry(CListBegin(list), type, member); \
|
||||
&elt->member != CListEnd(list); \
|
||||
elt = CListEntry(elt->member.next, type, member)) \
|
||||
for(type* elt = clist_entry(clist_begin(list), type, member); \
|
||||
&elt->member != clist_end(list); \
|
||||
elt = clist_entry(elt->member.next, type, member)) \
|
||||
|
||||
|
||||
#define for_each_in_clist_reverse(list, elt, type, member) \
|
||||
for(type* elt = CListEntry(CListLast(list), type, member); \
|
||||
&elt->member != CListEnd(list); \
|
||||
elt = CListEntry(elt->member.prev, type, member)) \
|
||||
for(type* elt = clist_entry(clist_last(list), type, member); \
|
||||
&elt->member != clist_end(list); \
|
||||
elt = clist_entry(elt->member.prev, type, member)) \
|
||||
|
||||
|
||||
#define for_each_in_clist_safe(list, elt, type, member) \
|
||||
for(type* elt = CListEntry(CListBegin(list), type, member), \
|
||||
*__tmp = CListEntry(elt->member.next, type, member); \
|
||||
&elt->member != CListEnd(list); \
|
||||
elt = CListEntry(&__tmp->member, type, member), \
|
||||
__tmp = CListEntry(elt->member.next, type, member)) \
|
||||
for(type* elt = clist_entry(clist_begin(list), type, member), \
|
||||
*__tmp = clist_entry(elt->member.next, type, member); \
|
||||
&elt->member != clist_end(list); \
|
||||
elt = clist_entry(&__tmp->member, type, member), \
|
||||
__tmp = clist_entry(elt->member.next, type, member)) \
|
||||
|
||||
|
||||
#define CListPush(a, b) CListInsert(a, b)
|
||||
#define CListInsertBefore(a, b) CListAppend(a, b)
|
||||
#define clist_push(a, b) clist_insert(a, b)
|
||||
#define clist_insert_before(a, b) clist_append(a, b)
|
||||
|
||||
#define CListPopEntry(list, type, member) (CListEmpty(list) ? 0 : CListEntry(CListPop(list), type, member))
|
||||
#define clist_pop_entry(list, type, member) (clist_empty(list) ? 0 : clist_entry(clist_pop(list), type, member))
|
||||
|
||||
static inline void CListInit(list_elt* info)
|
||||
static inline void clist_init(list_elt* info)
|
||||
{
|
||||
info->next = info->prev = info;
|
||||
}
|
||||
|
||||
static inline list_elt* CListBegin(list_elt* head)
|
||||
static inline list_elt* clist_begin(list_elt* head)
|
||||
{
|
||||
return(head->next ? head->next : head );
|
||||
}
|
||||
static inline list_elt* CListEnd(list_elt* head)
|
||||
static inline list_elt* clist_end(list_elt* head)
|
||||
{
|
||||
return(head);
|
||||
}
|
||||
|
||||
static inline list_elt* CListLast(list_elt* head)
|
||||
static inline list_elt* clist_last(list_elt* head)
|
||||
{
|
||||
return(head->prev ? head->prev : head);
|
||||
}
|
||||
|
||||
static inline void CListInsert(list_elt* head, list_elt* elt)
|
||||
static inline void clist_insert(list_elt* head, list_elt* elt)
|
||||
{
|
||||
elt->prev = head;
|
||||
elt->next = head->next;
|
||||
|
@ -313,15 +313,15 @@ static inline void CListInsert(list_elt* head, list_elt* elt)
|
|||
}
|
||||
head->next = elt;
|
||||
|
||||
ASSERT(elt->next != elt, "CListInsert(): can't insert an element into itself");
|
||||
ASSERT(elt->next != elt, "clist_insert(): can't insert an element into itself");
|
||||
}
|
||||
|
||||
static inline void CListAppend(list_elt* head, list_elt* elt)
|
||||
static inline void clist_append(list_elt* head, list_elt* elt)
|
||||
{
|
||||
CListInsert(head->prev, elt);
|
||||
clist_insert(head->prev, elt);
|
||||
}
|
||||
|
||||
static inline void CListCat(list_elt* head, list_elt* list)
|
||||
static inline void clist_cat(list_elt* head, list_elt* list)
|
||||
{
|
||||
if(head->prev)
|
||||
{
|
||||
|
@ -336,10 +336,10 @@ static inline void CListCat(list_elt* head, list_elt* list)
|
|||
{
|
||||
head->prev->next = head;
|
||||
}
|
||||
CListInit(list);
|
||||
clist_init(list);
|
||||
}
|
||||
|
||||
static inline void CListRemove(list_elt* elt)
|
||||
static inline void clist_remove(list_elt* elt)
|
||||
{
|
||||
if(elt->prev)
|
||||
{
|
||||
|
@ -352,12 +352,12 @@ static inline void CListRemove(list_elt* elt)
|
|||
elt->prev = elt->next = 0;
|
||||
}
|
||||
|
||||
static inline list_elt* CListPop(list_elt* head)
|
||||
static inline list_elt* clist_pop(list_elt* head)
|
||||
{
|
||||
list_elt* it = CListBegin(head);
|
||||
if(it != CListEnd(head))
|
||||
list_elt* it = clist_begin(head);
|
||||
if(it != clist_end(head))
|
||||
{
|
||||
CListRemove(it);
|
||||
clist_remove(it);
|
||||
return(it);
|
||||
}
|
||||
else
|
||||
|
@ -367,12 +367,12 @@ static inline list_elt* CListPop(list_elt* head)
|
|||
|
||||
}
|
||||
|
||||
static inline list_elt* CListPopBack(list_elt* head)
|
||||
static inline list_elt* clist_pop_back(list_elt* head)
|
||||
{
|
||||
list_elt* it = CListLast(head);
|
||||
if(it != CListEnd(head))
|
||||
list_elt* it = clist_last(head);
|
||||
if(it != clist_end(head))
|
||||
{
|
||||
CListRemove(it);
|
||||
clist_remove(it);
|
||||
return(it);
|
||||
}
|
||||
else
|
||||
|
@ -381,7 +381,7 @@ static inline list_elt* CListPopBack(list_elt* head)
|
|||
}
|
||||
}
|
||||
|
||||
static inline bool CListEmpty(list_elt* head)
|
||||
static inline bool clist_empty(list_elt* head)
|
||||
{
|
||||
return(head->next == 0 || head->next == head);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ void mem_pool_init_with_options(mem_pool* pool, u64 blockSize, mem_pool_options*
|
|||
{
|
||||
mem_arena_init_with_options(&pool->arena, &(mem_arena_options){.base = options->base, .reserve = options->reserve});
|
||||
pool->blockSize = ClampLowBound(blockSize, sizeof(list_info));
|
||||
ListInit(&pool->freeList);
|
||||
list_init(&pool->freeList);
|
||||
}
|
||||
|
||||
void mem_pool_release(mem_pool* pool)
|
||||
|
@ -86,26 +86,26 @@ void mem_pool_release(mem_pool* pool)
|
|||
|
||||
void* mem_pool_alloc(mem_pool* pool)
|
||||
{
|
||||
if(ListEmpty(&pool->freeList))
|
||||
if(list_empty(&pool->freeList))
|
||||
{
|
||||
return(mem_arena_alloc(&pool->arena, pool->blockSize));
|
||||
}
|
||||
else
|
||||
{
|
||||
return(ListPop(&pool->freeList));
|
||||
return(list_pop(&pool->freeList));
|
||||
}
|
||||
}
|
||||
|
||||
void mem_pool_recycle(mem_pool* pool, void* ptr)
|
||||
{
|
||||
ASSERT((((char*)ptr) >= pool->arena.ptr) && (((char*)ptr) < (pool->arena.ptr + pool->arena.offset)));
|
||||
ListPush(&pool->freeList, (list_elt*)ptr);
|
||||
list_push(&pool->freeList, (list_elt*)ptr);
|
||||
}
|
||||
|
||||
void mem_pool_clear(mem_pool* pool)
|
||||
{
|
||||
mem_arena_clear(&pool->arena);
|
||||
ListInit(&pool->freeList);
|
||||
list_init(&pool->freeList);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ char* str8_to_cstring(mem_arena* arena, str8 string)
|
|||
|
||||
void str8_list_init(str8_list* list)
|
||||
{
|
||||
ListInit(&list->list);
|
||||
list_init(&list->list);
|
||||
list->eltCount = 0;
|
||||
list->len = 0;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ void str8_list_push(mem_arena* arena, str8_list* list, str8 str)
|
|||
{
|
||||
str8_elt* elt = mem_arena_alloc_type(arena, str8_elt);
|
||||
elt->string = str;
|
||||
ListAppend(&list->list, &elt->listElt);
|
||||
list_append(&list->list, &elt->listElt);
|
||||
list->eltCount++;
|
||||
list->len += str.len;
|
||||
}
|
||||
|
@ -146,15 +146,15 @@ str8 str8_list_collate(mem_arena* arena, str8_list list, str8 prefix, str8 separ
|
|||
memcpy(dst, prefix.ptr, prefix.len);
|
||||
dst += prefix.len;
|
||||
|
||||
str8_elt* elt = ListFirstEntry(&list.list, str8_elt, listElt);
|
||||
str8_elt* elt = list_first_entry(&list.list, str8_elt, listElt);
|
||||
if(elt)
|
||||
{
|
||||
memcpy(dst, elt->string.ptr, elt->string.len);
|
||||
dst += elt->string.len;
|
||||
elt = ListNextEntry(&list.list, elt, str8_elt, listElt);
|
||||
elt = list_next_entry(&list.list, elt, str8_elt, listElt);
|
||||
}
|
||||
|
||||
for( ; elt != 0; elt = ListNextEntry(&list.list, elt, str8_elt, listElt))
|
||||
for( ; elt != 0; elt = list_next_entry(&list.list, elt, str8_elt, listElt))
|
||||
{
|
||||
memcpy(dst, separator.ptr, separator.len);
|
||||
dst += separator.len;
|
||||
|
@ -174,7 +174,7 @@ str8 str8_list_join(mem_arena* arena, str8_list list)
|
|||
str8_list str8_split(mem_arena* arena, str8 str, str8_list separators)
|
||||
{
|
||||
str8_list list = {0};
|
||||
ListInit(&list.list);
|
||||
list_init(&list.list);
|
||||
|
||||
char* ptr = str.ptr;
|
||||
char* end = str.ptr + str.len;
|
||||
|
@ -261,7 +261,7 @@ str32 str32_push_slice(mem_arena* arena, str32 s, u64 start, u64 end)
|
|||
|
||||
void str32_list_init(str32_list* list)
|
||||
{
|
||||
ListInit(&list->list);
|
||||
list_init(&list->list);
|
||||
list->eltCount = 0;
|
||||
list->len = 0;
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ void str32_list_push(mem_arena* arena, str32_list* list, str32 str)
|
|||
{
|
||||
str32_elt* elt = mem_arena_alloc_type(arena, str32_elt);
|
||||
elt->string = str;
|
||||
ListAppend(&list->list, &elt->listElt);
|
||||
list_append(&list->list, &elt->listElt);
|
||||
list->eltCount++;
|
||||
list->len += str.len;
|
||||
}
|
||||
|
@ -284,15 +284,15 @@ str32 str32_list_collate(mem_arena* arena, str32_list list, str32 prefix, str32
|
|||
memcpy(dst, prefix.ptr, prefix.len*sizeof(u32));
|
||||
dst += prefix.len*sizeof(u32);
|
||||
|
||||
str32_elt* elt = ListFirstEntry(&list.list, str32_elt, listElt);
|
||||
str32_elt* elt = list_first_entry(&list.list, str32_elt, listElt);
|
||||
if(elt)
|
||||
{
|
||||
memcpy(dst, elt->string.ptr, elt->string.len*sizeof(u32));
|
||||
dst += elt->string.len*sizeof(u32);
|
||||
elt = ListNextEntry(&list.list, elt, str32_elt, listElt);
|
||||
elt = list_next_entry(&list.list, elt, str32_elt, listElt);
|
||||
}
|
||||
|
||||
for( ; elt != 0; elt = ListNextEntry(&list.list, elt, str32_elt, listElt))
|
||||
for( ; elt != 0; elt = list_next_entry(&list.list, elt, str32_elt, listElt))
|
||||
{
|
||||
memcpy(dst, separator.ptr, separator.len*sizeof(u32));
|
||||
dst += separator.len*sizeof(u32);
|
||||
|
|
Loading…
Reference in New Issue