1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 05:50:26 +02:00

copy-space: refactor to copy_space_can_allocate

This commit is contained in:
Andy Wingo 2025-01-24 16:11:11 +01:00
parent 68e3a692f5
commit b517464d7f
2 changed files with 6 additions and 6 deletions

View file

@ -567,16 +567,16 @@ copy_space_finish_gc(struct copy_space *space, int is_minor_gc) {
space->in_gc = 0; space->in_gc = 0;
} }
static int static size_t
copy_space_can_allocate(struct copy_space *space, size_t bytes) { copy_space_can_allocate(struct copy_space *space, size_t bytes) {
// With lock! // With lock!
size_t count = 0;
for (struct copy_space_block *empties = space->empty.list.head; for (struct copy_space_block *empties = space->empty.list.head;
empties; empties && count < bytes;
empties = empties->next) { empties = empties->next) {
if (bytes <= COPY_SPACE_REGION_SIZE) return 1; count += COPY_SPACE_REGION_SIZE;
bytes -= COPY_SPACE_REGION_SIZE;
} }
return 0; return count;
} }
static void static void

View file

@ -813,7 +813,7 @@ heap_can_minor_gc(struct gc_heap *heap) {
struct copy_space *new_space = heap_new_space(heap); struct copy_space *new_space = heap_new_space(heap);
struct copy_space *old_space = heap_old_space(heap); struct copy_space *old_space = heap_old_space(heap);
size_t nursery_size = heap_nursery_size(heap); size_t nursery_size = heap_nursery_size(heap);
return copy_space_can_allocate(old_space, nursery_size); return copy_space_can_allocate(old_space, nursery_size) >= nursery_size;
} }
static enum gc_collection_kind static enum gc_collection_kind