Skip to content

Commit 1b65282

Browse files
hardcode and look up magic numbers
instead of computing them on page add
1 parent 5c71c8c commit 1b65282

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

gc/default/default.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,13 @@ heap_page_in_global_empty_pages_pool(rb_objspace_t *objspace, struct heap_page *
841841
#define GET_PAGE_HEADER(x) (&GET_PAGE_BODY(x)->header)
842842
#define GET_HEAP_PAGE(x) (GET_PAGE_HEADER(x)->page)
843843

844-
static inline uint32_t
845-
compute_slot_div_magic(unsigned short slot_size)
846-
{
847-
return (uint32_t)(UINT32_MAX / slot_size) + 1;
848-
}
844+
static const uint32_t slot_div_magics[HEAP_COUNT] = {
845+
0x06666667U,
846+
0x03333334U,
847+
0x0199999aU,
848+
0x00cccccdU,
849+
0x00666667U,
850+
};
849851

850852
static inline size_t
851853
slot_index_for_offset(size_t offset, uint32_t div_magic)
@@ -2006,7 +2008,7 @@ heap_add_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *page)
20062008
page->start = start;
20072009
page->total_slots = slot_count;
20082010
page->slot_size = heap->slot_size;
2009-
page->slot_div_magic = compute_slot_div_magic(heap->slot_size);
2011+
page->slot_div_magic = slot_div_magics[heap - heaps];
20102012
page->heap = heap;
20112013

20122014
asan_unlock_freelist(page);

0 commit comments

Comments
 (0)