wingo pushed a commit to branch wip-whippet
in repository guile.

commit b517464d7f1301710e3249129b2b67b301b9db28
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Fri Jan 24 16:11:11 2025 +0100

    copy-space: refactor to copy_space_can_allocate
---
 src/copy-space.h | 10 +++++-----
 src/pcc.c        |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/copy-space.h b/src/copy-space.h
index d32de0298..19b00e5fa 100644
--- a/src/copy-space.h
+++ b/src/copy-space.h
@@ -567,16 +567,16 @@ copy_space_finish_gc(struct copy_space *space, int 
is_minor_gc) {
   space->in_gc = 0;
 }
 
-static int
+static size_t
 copy_space_can_allocate(struct copy_space *space, size_t bytes) {
   // With lock!
+  size_t count = 0;
   for (struct copy_space_block *empties = space->empty.list.head;
-       empties;
+       empties && count < bytes;
        empties = empties->next) {
-    if (bytes <= COPY_SPACE_REGION_SIZE) return 1;
-    bytes -= COPY_SPACE_REGION_SIZE;
+    count += COPY_SPACE_REGION_SIZE;
   }
-  return 0;
+  return count;
 }
 
 static void
diff --git a/src/pcc.c b/src/pcc.c
index dd91a0317..1abf70bf6 100644
--- a/src/pcc.c
+++ b/src/pcc.c
@@ -813,7 +813,7 @@ heap_can_minor_gc(struct gc_heap *heap) {
   struct copy_space *new_space = heap_new_space(heap);
   struct copy_space *old_space = heap_old_space(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

Reply via email to