From 227ebb9daaaab79b8d8f8f9dc5b12a91500e698c Mon Sep 17 00:00:00 2001 From: dearblue Date: Thu, 14 Mar 2024 22:12:35 +0900 Subject: [PATCH] Simplify expansion of mt and iv a bit --- src/class.c | 5 +---- src/variable.c | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/class.c b/src/class.c index c5eba0299..e1305bdb4 100644 --- a/src/class.c +++ b/src/class.c @@ -67,12 +67,9 @@ static void mt_rehash(mrb_state *mrb, mt_tbl *t) { int old_alloc = t->alloc; - int new_alloc = old_alloc+8; + int new_alloc = old_alloc > 0 ? old_alloc << 1 : 8; union mt_ptr *old_ptr = t->ptr; - khash_power2(new_alloc); - if (old_alloc == new_alloc) return; - t->ptr = (union mt_ptr*)mrb_calloc(mrb, sizeof(union mt_ptr)+sizeof(mrb_sym), new_alloc); t->alloc = new_alloc; t->size = 0; diff --git a/src/variable.c b/src/variable.c index 4c51a8a61..94fff7119 100644 --- a/src/variable.c +++ b/src/variable.c @@ -43,11 +43,9 @@ static void iv_rehash(mrb_state *mrb, iv_tbl *t) { int old_alloc = t->alloc; - int new_alloc = old_alloc+4; + int new_alloc = old_alloc > 0 ? old_alloc << 1 : 4; mrb_value *old_ptr = t->ptr; - khash_power2(new_alloc); - t->ptr = (mrb_value*)mrb_calloc(mrb, sizeof(mrb_value)+sizeof(mrb_sym), new_alloc); t->size = 0; t->alloc = new_alloc;