Skip to content

Commit 7faaca5

Browse files
C: Fix O(n) linked list walk in hb_arena_append_page() (#1380)
This PR changes the way we add pages in the arena allocator, instead of seeking to the tail page starting from the head, we directly use the tail page. Additionally this PR asserts that if the head page is null, the tail page also should be null. --------- Co-authored-by: Michael Kohl <me@citizen428.net>
1 parent f037dbb commit 7faaca5

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/util/hb_arena.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,12 @@ static bool hb_arena_append_page(hb_arena_T* allocator, size_t page_size) {
7070
page->position = 0;
7171

7272
if (allocator->head == NULL) {
73+
assert(allocator->tail == NULL);
74+
7375
allocator->head = page;
7476
allocator->tail = page;
7577
} else {
76-
hb_arena_page_T* last = allocator->head;
77-
78-
while (last->next != NULL) {
79-
last = last->next;
80-
}
81-
82-
last->next = page;
78+
allocator->tail->next = page;
8379
allocator->tail = page;
8480
}
8581

0 commit comments

Comments
 (0)