diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-12-13 01:32:17 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-12-14 11:57:46 +0900 |
commit | fa63052be19b26d39b22689ad9969aa83909809e (patch) | |
tree | fcb5a830f12de697a24571d4ad973d0d0b45b240 /vm_insnhelper.c | |
parent | 85a7f723c300c45c8fff40c2595422e13a8d9237 (diff) |
create ccs with 0 capa
ccs is created with default 4 capa, but it is too much, so start
with 0 and extend to 1, 2, 4, 8, ...
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3892
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 9a94b1070b..5e77b7fbf2 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1534,11 +1534,11 @@ vm_ccs_create(VALUE klass, const rb_callable_method_entry_t *cme) #if VM_CHECK_MODE > 0 ccs->debug_sig = ~(VALUE)ccs; #endif - ccs->capa = 4; + ccs->capa = 0; ccs->len = 0; RB_OBJ_WRITE(klass, &ccs->cme, cme); METHOD_ENTRY_CACHED_SET((rb_callable_method_entry_t *)cme); - ccs->entries = ALLOC_N(struct rb_class_cc_entries_entry, ccs->capa); + ccs->entries = NULL; return ccs; } @@ -1553,12 +1553,14 @@ vm_ccs_push(VALUE klass, struct rb_class_cc_entries *ccs, const struct rb_callin } if (UNLIKELY(ccs->len == ccs->capa)) { - const int nsize = ccs->capa * 2; - struct rb_class_cc_entries_entry *nents = ALLOC_N(struct rb_class_cc_entries_entry, nsize); - ccs->capa = nsize; - MEMCPY(nents, &ccs->entries[0], struct rb_class_cc_entries_entry, ccs->len); - ruby_xfree(ccs->entries); - ccs->entries = nents; + if (ccs->capa == 0) { + ccs->capa = 1; + ccs->entries = ALLOC_N(struct rb_class_cc_entries_entry, ccs->capa); + } + else { + ccs->capa *= 2; + REALLOC_N(ccs->entries, struct rb_class_cc_entries_entry, ccs->capa); + } } VM_ASSERT(ccs->len < ccs->capa); |