gc: Speed up new_object by adding new blocks to the front of the list
This way we don't have to traverse the whole list to the very end every time we want a new object.
This commit is contained in:
parent
906ae3eac4
commit
8233e94ab3
1 changed files with 6 additions and 5 deletions
11
src/gc.c
11
src/gc.c
|
|
@ -124,17 +124,17 @@ new_block(struct gc *gc)
|
|||
static struct gc_object *
|
||||
new_object_inner(struct gc *gc)
|
||||
{
|
||||
struct gc_block **cur = &gc->block;
|
||||
struct gc_block *cur = gc->block;
|
||||
|
||||
while (*cur != NULL) {
|
||||
struct gc_block *block = *cur;
|
||||
while (cur != NULL) {
|
||||
struct gc_block *block = cur;
|
||||
for (size_t i = 0; i < GC_OBJECTS_PER_BLOCK; i++) {
|
||||
if (block->objects[i].status == GC_STATUS_FREE) {
|
||||
return &block->objects[i];
|
||||
}
|
||||
}
|
||||
|
||||
cur = &block->next;
|
||||
cur = block->next;
|
||||
}
|
||||
|
||||
struct gc_block *nb = new_block(gc);
|
||||
|
|
@ -142,7 +142,8 @@ new_object_inner(struct gc *gc)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
*cur = nb;
|
||||
nb->next = gc->block;
|
||||
gc->block = nb;
|
||||
|
||||
return &nb->objects[0];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue