diff --git a/src/class.c b/src/class.c index ade36fad6..af3ae4357 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 4a373f33f..c213f4211 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;