diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-03-10 23:03:06 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-03-10 23:03:06 +0000 |
commit | 2abf664151aa8ea7769d2a6d0c7ebe82bddaba7c (patch) | |
tree | e1fa758c5bfddf7d70051a2158526e895fa36041 /eval.c | |
parent | eccf9342c753ceeebe9187ac435ceae9ddad3402 (diff) |
* eval.c (massign): remove unnecessary array unpacking; it should
be handled before massign() by svalue_to_mrhs().
* eval.c (svalue_to_mrhs): '*a = v' value conversion to avalue
(i.e. [1] => [[1]], [1,2] => [1,2]).
* eval.c (rb_eval): use svalue_to_mrhs.
* eval.c (rb_yield_0): ditto.
* eval.c (proc_invoke): break from "Proc#yield" is legal.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 58 |
1 files changed, 27 insertions, 31 deletions
@@ -2222,6 +2222,25 @@ svalue_to_avalue(v) } static VALUE +svalue_to_mrhs(v, lhs) + VALUE v; + NODE *lhs; +{ + VALUE tmp; + + if (v == Qundef) return rb_ary_new2(0); + tmp = rb_check_array_type(v); + + if (NIL_P(tmp)) { + return rb_ary_new3(1, v); + } + if (!lhs && RARRAY(tmp)->len <= 1) { + return rb_ary_new3(1, tmp); + } + return tmp; +} + +static VALUE class_prefix(self, cpath) VALUE self; NODE *cpath; @@ -2978,7 +2997,7 @@ rb_eval(self, n) break; case NODE_MASGN: - result = svalue_to_avalue(rb_eval(self, node->nd_value)); + result = svalue_to_mrhs(rb_eval(self, node->nd_value), node->nd_head); result = massign(self, node, result, 0); break; @@ -3910,7 +3929,9 @@ rb_yield_0(val, self, klass, pcall, avalue) } } else if (nd_type(block->var) == NODE_MASGN) { - if (!avalue) val = svalue_to_avalue(val); + if (!avalue) { + val = svalue_to_mrhs(val, block->var->nd_head); + } massign(self, block->var, val, pcall); } else { @@ -4024,34 +4045,13 @@ massign(self, node, val, pcall) int pcall; { NODE *list; - VALUE tmp; long i = 0, len; len = RARRAY(val)->len; list = node->nd_head; - if (len == 1 && list) { - VALUE v = RARRAY(val)->ptr[0]; - tmp = rb_check_array_type(v); - - if (NIL_P(tmp)) { - assign(self, list->nd_head, v, pcall); - list = list->nd_next; - i = 1; - } - else { - len = RARRAY(tmp)->len; - for (i=0; list && i<len; i++) { - assign(self, list->nd_head, RARRAY(tmp)->ptr[i], pcall); - list = list->nd_next; - } - } - } - else { - for (; list && i<len; i++) { - assign(self, list->nd_head, RARRAY(val)->ptr[i], pcall); - list = list->nd_next; - } - tmp = val; + for (; list && i<len; i++) { + assign(self, list->nd_head, RARRAY(val)->ptr[i], pcall); + list = list->nd_next; } if (pcall && list) goto arg_error; if (node->nd_args) { @@ -4059,7 +4059,7 @@ massign(self, node, val, pcall) /* no check for mere `*' */ } else if (!list && i<len) { - assign(self, node->nd_args, rb_ary_new4(len-i, RARRAY(tmp)->ptr+i), pcall); + assign(self, node->nd_args, rb_ary_new4(len-i, RARRAY(val)->ptr+i), pcall); } else { assign(self, node->nd_args, rb_ary_new2(0), pcall); @@ -6691,7 +6691,6 @@ proc_invoke(proc, args, pcall, self) PUSH_ITER(ITER_CUR); ruby_frame->iter = ITER_CUR; - PUSH_TAG(PROT_NONE); state = EXEC_TAG(); if (state == 0) { @@ -6713,9 +6712,6 @@ proc_invoke(proc, args, pcall, self) case 0: break; case TAG_BREAK: - if (!pcall && orphan) { - localjump_error("break from proc-closure", prot_tag->retval); - } result = prot_tag->retval; break; case TAG_RETRY: |