summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-27 05:35:47 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-27 05:35:47 (GMT)
commit27db7101c65a7b00028de227f2743106b33c3c83 (patch)
treef3f0986e9f098bbf868b546482e8dd6cac2617b4 /vm_insnhelper.c
parentfe18a62347133c95242a4304840a41982e190c21 (diff)
vm_insnhelper.c: avoid intermediate array
* vm_insnhelper.c (vm_expandarray): get rid of creating intermediate Array object when conversion failed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 8b9bdeb..0fbf39d2 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1237,16 +1237,20 @@ vm_expandarray(rb_control_frame_t *cfp, VALUE ary, rb_num_t num, int flag)
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;