ruby-changes:64135
From: Koichi <ko1@a...>
Date: Mon, 14 Dec 2020 11:58:11 +0900 (JST)
Subject: [ruby-changes:64135] fa63052be1 (master): create ccs with 0 capa
https://git.ruby-lang.org/ruby.git/commit/?id=fa63052be1 From fa63052be19b26d39b22689ad9969aa83909809e Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Sun, 13 Dec 2020 01:32:17 +0900 Subject: 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, ... diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 9a94b10..5e77b7f 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) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1534 #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 https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1553 } 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); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/