ruby-changes:46302
From: shyouhei <ko1@a...>
Date: Thu, 20 Apr 2017 19:32:15 +0900 (JST)
Subject: [ruby-changes:46302] shyouhei:r58416 (trunk): refactor torexp to use routine in array.c
shyouhei 2017-04-20 19:32:08 +0900 (Thu, 20 Apr 2017) New Revision: 58416 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58416 Log: refactor torexp to use routine in array.c Found a part where copy&paste can be eliminated. Reduces vm_exec_core from 26,228 bytes to 26,176 bytes in size on my machine. I believe it does not affect any runtime performance. ---- * array.c (rb_ary_tmp_new_from_values): extend existing rb_ary_new_from_values function so that it can take additional value for klass. * array.c (rb_ary_new_from_values): use the new function. * insns.def (toregexp): ditto. Modified files: trunk/array.c trunk/insns.def Index: insns.def =================================================================== --- insns.def (revision 58415) +++ insns.def (revision 58416) @@ -388,11 +388,8 @@ toregexp https://github.com/ruby/ruby/blob/trunk/insns.def#L388 (VALUE val) // inc += 1 - cnt; { VALUE rb_reg_new_ary(VALUE ary, int options); - rb_num_t i; - const VALUE ary = rb_ary_tmp_new(cnt); - for (i = 0; i < cnt; i++) { - rb_ary_store(ary, cnt-i-1, TOPN(i)); - } + VALUE rb_ary_tmp_new_from_values(VALUE, long, const VALUE *); + const VALUE ary = rb_ary_tmp_new_from_values(0, cnt, STACK_ADDR_FROM_TOP(cnt)); POPN(cnt); val = rb_reg_new_ary(ary, (int)opt); rb_ary_clear(ary); Index: array.c =================================================================== --- array.c (revision 58415) +++ array.c (revision 58416) @@ -515,11 +515,11 @@ VALUE https://github.com/ruby/ruby/blob/trunk/array.c#L515 } VALUE -rb_ary_new_from_values(long n, const VALUE *elts) +rb_ary_tmp_new_from_values(VALUE klass, long n, const VALUE *elts) { VALUE ary; - ary = rb_ary_new2(n); + ary = ary_new(klass, n); if (n > 0 && elts) { ary_memcpy(ary, 0, n, elts); ARY_SET_LEN(ary, n); @@ -529,6 +529,12 @@ rb_ary_new_from_values(long n, const VAL https://github.com/ruby/ruby/blob/trunk/array.c#L529 } VALUE +rb_ary_new_from_values(long n, const VALUE *elts) +{ + return rb_ary_tmp_new_from_values(rb_cArray, n, elts); +} + +VALUE rb_ary_tmp_new(long capa) { return ary_new(0, capa); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/