1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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, ...
This commit is contained in:
Koichi Sasada 2020-12-13 01:32:17 +09:00
parent 85a7f723c3
commit fa63052be1
Notes: git 2020-12-14 11:58:13 +09:00

View file

@ -1534,11 +1534,11 @@ vm_ccs_create(VALUE klass, const rb_callable_method_entry_t *cme)
#if VM_CHECK_MODE > 0 #if VM_CHECK_MODE > 0
ccs->debug_sig = ~(VALUE)ccs; ccs->debug_sig = ~(VALUE)ccs;
#endif #endif
ccs->capa = 4; ccs->capa = 0;
ccs->len = 0; ccs->len = 0;
RB_OBJ_WRITE(klass, &ccs->cme, cme); RB_OBJ_WRITE(klass, &ccs->cme, cme);
METHOD_ENTRY_CACHED_SET((rb_callable_method_entry_t *)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; 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)) { if (UNLIKELY(ccs->len == ccs->capa)) {
const int nsize = ccs->capa * 2; if (ccs->capa == 0) {
struct rb_class_cc_entries_entry *nents = ALLOC_N(struct rb_class_cc_entries_entry, nsize); ccs->capa = 1;
ccs->capa = nsize; ccs->entries = ALLOC_N(struct rb_class_cc_entries_entry, ccs->capa);
MEMCPY(nents, &ccs->entries[0], struct rb_class_cc_entries_entry, ccs->len); }
ruby_xfree(ccs->entries); else {
ccs->entries = nents; ccs->capa *= 2;
REALLOC_N(ccs->entries, struct rb_class_cc_entries_entry, ccs->capa);
}
} }
VM_ASSERT(ccs->len < ccs->capa); VM_ASSERT(ccs->len < ccs->capa);