diff options
author | Matt Valentine-House <matt@eightbitraptor.com> | 2023-08-08 21:09:37 +0100 |
---|---|---|
committer | Matt Valentine-House <matt@eightbitraptor.com> | 2023-09-18 14:34:38 +0100 |
commit | d3852f71e4924b16a9fed6b43b86d11af036c432 (patch) | |
tree | ea49313517887614e753f44d0c54e9cfab44f1c7 /gc.c | |
parent | c492a7f8776fd384fc740f806536ec33c6fba59c (diff) |
Enable different heap sort methods during compaction
pass the sorting function in as a function pointer so we don't always
sort by how empty a page is
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -697,6 +697,8 @@ typedef struct mark_stack { #define SIZE_POOL_EDEN_HEAP(size_pool) (&(size_pool)->eden_heap) #define SIZE_POOL_TOMB_HEAP(size_pool) (&(size_pool)->tomb_heap) +typedef int (*gc_compact_compare_func)(const void *l, const void *r, void *d); + typedef struct rb_heap_struct { struct heap_page *free_pages; struct ccan_list_head pages; @@ -9933,7 +9935,7 @@ compare_free_slots(const void *left, const void *right, void *dummy) } static void -gc_sort_heap_by_empty_slots(rb_objspace_t *objspace) +gc_sort_heap_by_compare_func(rb_objspace_t *objspace, gc_compact_compare_func compare_func) { for (int j = 0; j < SIZE_POOL_COUNT; j++) { rb_size_pool_t *size_pool = &size_pools[j]; @@ -9953,7 +9955,7 @@ gc_sort_heap_by_empty_slots(rb_objspace_t *objspace) /* Sort the heap so "filled pages" are first. `heap_add_page` adds to the * head of the list, so empty pages will end up at the start of the heap */ - ruby_qsort(page_list, total_pages, sizeof(struct heap_page *), compare_free_slots, NULL); + ruby_qsort(page_list, total_pages, sizeof(struct heap_page *), compare_func, NULL); /* Reset the eden heap */ ccan_list_head_init(&SIZE_POOL_EDEN_HEAP(size_pool)->pages); @@ -10893,7 +10895,7 @@ gc_verify_compaction_references(rb_execution_context_t *ec, VALUE self, VALUE do } if (RTEST(toward_empty)) { - gc_sort_heap_by_empty_slots(objspace); + gc_sort_heap_by_compare_func(objspace, compare_free_slots); } } RB_VM_LOCK_LEAVE(); |