summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-15 19:13:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-15 19:13:07 +0000
commit20748861d4fa27997a174e4511b9454456483e91 (patch)
tree614c213950b4ceb7037ef644f5b90af1442adfb0 /iseq.c
parent5f2a4d15a7564f85c086362a1ffbf1ed5623a46b (diff)
iseq.c: intermediate arrays
* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset): hide and clear intermediate array objects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/iseq.c b/iseq.c
index 1338981..015c860 100644
--- a/iseq.c
+++ b/iseq.c
@@ -567,14 +567,15 @@ rb_method_for_self_aref(VALUE name, VALUE arg)
ISEQ_TYPE_METHOD, &COMPILE_OPTION_DEFAULT);
misc = params = rb_hash_new(); /* empty */
- locals = exception = rb_ary_new(); /* empty */
- body = rb_ary_new();
+ locals = exception = rb_ary_tmp_new(0); /* empty */
+ body = rb_ary_tmp_new(5);
#define S(s) ID2SYM(rb_intern(#s))
+#define ADD(a) rb_ary_push(body, rb_obj_hide(a))
/* def name; self[arg]; end */
- rb_ary_push(body, lineno);
- rb_ary_push(body, rb_ary_new3(1, S(putself)));
- rb_ary_push(body, rb_ary_new3(2, S(putobject), arg));
+ ADD(lineno);
+ ADD(rb_ary_new3(1, S(putself)));
+ ADD(rb_ary_new3(2, S(putobject), arg));
/* {:mid=>:[], :flag=>264, :blockptr=>nil, :orig_argc=>1} */
send_arg = rb_hash_new();
@@ -584,13 +585,16 @@ rb_method_for_self_aref(VALUE name, VALUE arg)
rb_hash_aset(send_arg, S(orig_argc), INT2FIX(1));
/* we do not want opt_aref for struct */
- rb_ary_push(body, rb_ary_new3(2, S(opt_send_without_block), send_arg));
- rb_ary_push(body, rb_ary_new3(1, S(leave)));
+ ADD(rb_ary_new3(2, S(opt_send_without_block), send_arg));
+ ADD(rb_ary_new3(1, S(leave)));
#undef S
+#undef ADD
rb_iseq_build_from_ary(iseq, misc, locals, params, exception, body);
cleanup_iseq_build(iseq);
+ rb_ary_clear(body);
+
return iseqval;
}
@@ -614,20 +618,21 @@ rb_method_for_self_aset(VALUE name, VALUE arg)
/* def name=(val); self[arg] = val; end */
#define S(s) ID2SYM(rb_intern(#s))
+#define ADD(a) rb_ary_push(body, rb_obj_hide(a))
misc = rb_hash_new(); /* empty */
- locals = rb_ary_new3(1, S(val));
+ locals = rb_obj_hide(rb_ary_new3(1, S(val)));
params = rb_hash_new();
- exception = rb_ary_new(); /* empty */
- body = rb_ary_new();
+ exception = rb_ary_tmp_new(0); /* empty */
+ body = rb_ary_tmp_new(9);
rb_hash_aset(params, S(lead_num), INT2FIX(1));
- rb_ary_push(body, lineno);
- rb_ary_push(body, rb_ary_new3(1, S(putnil)));
- rb_ary_push(body, rb_ary_new3(1, S(putself)));
- rb_ary_push(body, rb_ary_new3(2, S(putobject), arg));
- rb_ary_push(body, rb_ary_new3(3, S(getlocal), INT2FIX(2), INT2FIX(0)));
- rb_ary_push(body, rb_ary_new3(2, S(setn), INT2FIX(3)));
+ ADD(lineno);
+ ADD(rb_ary_new3(1, S(putnil)));
+ ADD(rb_ary_new3(1, S(putself)));
+ ADD(rb_ary_new3(2, S(putobject), arg));
+ ADD(rb_ary_new3(3, S(getlocal), INT2FIX(2), INT2FIX(0)));
+ ADD(rb_ary_new3(2, S(setn), INT2FIX(3)));
/* {:mid=>:[]=, :flag=>264, :blockptr=>nil, :orig_argc=>2} */
send_arg = rb_hash_new();
@@ -637,15 +642,18 @@ rb_method_for_self_aset(VALUE name, VALUE arg)
rb_hash_aset(send_arg, S(orig_argc), INT2FIX(2));
/* we do not want opt_aset for struct */
- rb_ary_push(body, rb_ary_new3(2, S(opt_send_without_block), send_arg));
+ ADD(rb_ary_new3(2, S(opt_send_without_block), send_arg));
- rb_ary_push(body, rb_ary_new3(1, S(pop)));
- rb_ary_push(body, rb_ary_new3(1, S(leave)));
+ ADD(rb_ary_new3(1, S(pop)));
+ ADD(rb_ary_new3(1, S(leave)));
#undef S
+#undef ADD
rb_iseq_build_from_ary(iseq, misc, locals, params, exception, body);
cleanup_iseq_build(iseq);
+ rb_ary_clear(body);
+
return iseqval;
}