ruby-changes:49951
From: nobu <ko1@a...>
Date: Sat, 27 Jan 2018 14:35:53 +0900 (JST)
Subject: [ruby-changes:49951] nobu:r62069 (trunk): vm_insnhelper.c: avoid intermediate array
nobu 2018-01-27 14:35:47 +0900 (Sat, 27 Jan 2018) New Revision: 62069 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62069 Log: vm_insnhelper.c: avoid intermediate array * vm_insnhelper.c (vm_expandarray): get rid of creating intermediate Array object when conversion failed. Modified files: trunk/vm_insnhelper.c Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 62068) +++ vm_insnhelper.c (revision 62069) @@ -1237,16 +1237,20 @@ vm_expandarray(rb_control_frame_t *cfp, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1237 VALUE *base = cfp->sp; const VALUE *ptr; rb_num_t len; + const VALUE obj = ary; - if (!RB_TYPE_P(ary, T_ARRAY)) { - ary = rb_ary_to_ary(ary); + if (!RB_TYPE_P(ary, T_ARRAY) && NIL_P(ary = rb_check_array_type(ary))) { + ary = obj; + ptr = &ary; + len = 1; + } + else { + ptr = RARRAY_CONST_PTR(ary); + len = (rb_num_t)RARRAY_LEN(ary); } cfp->sp += space_size; - ptr = RARRAY_CONST_PTR(ary); - len = (rb_num_t)RARRAY_LEN(ary); - if (flag & 0x02) { /* post: ..., nil ,ary[-1], ..., ary[0..-num] # top */ rb_num_t i = 0, j; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/