1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* compile.c (compile_dstr_fragments): reduced needless literal.

* parse.y (xstring, regexp, dsym, literal_concat, evstr2dstr):
  literal at the top of dstr is no longer needed if it is empty,
  since concatstrings and toregexp always create new strings.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-07-20 10:01:05 +00:00
parent abc20ed0f4
commit 5a392c71db
4 changed files with 25 additions and 10 deletions

View file

@ -1,3 +1,11 @@
Mon Jul 20 19:00:58 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (compile_dstr_fragments): reduced needless literal.
* parse.y (xstring, regexp, dsym, literal_concat, evstr2dstr):
literal at the top of dstr is no longer needed if it is empty,
since concatstrings and toregexp always create new strings.
Mon Jul 20 12:51:39 2009 wanabe <s.wanabe@gmail.com> Mon Jul 20 12:51:39 2009 wanabe <s.wanabe@gmail.com>
* lib/matrix.rb (Matrix#rank): revert a part of r20859 to avoid * lib/matrix.rb (Matrix#rank): revert a part of r20859 to avoid
@ -27,7 +35,7 @@ Sun Jul 19 20:41:24 2009 Tadayoshi Funaba <tadf@dotrb.org>
Sun Jul 19 17:32:37 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Jul 19 17:32:37 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (io_read): should taint the result. [ruby-dev:38826] * io.c (io_read): should taint the result. [ruby-dev:38826]
Sun Jul 19 11:00:14 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Jul 19 11:00:14 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>

View file

@ -2143,11 +2143,14 @@ compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int *cntp
{ {
NODE *list = node->nd_next; NODE *list = node->nd_next;
VALUE lit = node->nd_lit; VALUE lit = node->nd_lit;
int cnt = 1; int cnt = 0;
debugp_param("nd_lit", lit); debugp_param("nd_lit", lit);
hide_obj(lit); if (!NIL_P(lit)) {
ADD_INSN1(ret, nd_line(node), putobject, lit); hide_obj(lit);
cnt++;
ADD_INSN1(ret, nd_line(node), putobject, lit);
}
while (list) { while (list) {
COMPILE(ret, "each string", list->nd_head); COMPILE(ret, "each string", list->nd_head);

12
parse.y
View file

@ -3806,7 +3806,7 @@ xstring : tXSTRING_BEG xstring_contents tSTRING_END
nd_set_type(node, NODE_DXSTR); nd_set_type(node, NODE_DXSTR);
break; break;
default: default:
node = NEW_NODE(NODE_DXSTR, STR_NEW0(), 1, NEW_LIST(node)); node = NEW_NODE(NODE_DXSTR, Qnil, 1, NEW_LIST(node));
break; break;
} }
} }
@ -3835,7 +3835,7 @@ regexp : tREGEXP_BEG xstring_contents tREGEXP_END
} }
break; break;
default: default:
node = NEW_NODE(NODE_DSTR, STR_NEW0(), 1, NEW_LIST(node)); node = NEW_NODE(NODE_DSTR, Qnil, 1, NEW_LIST(node));
case NODE_DSTR: case NODE_DSTR:
if (options & RE_OPTION_ONCE) { if (options & RE_OPTION_ONCE) {
nd_set_type(node, NODE_DREGX_ONCE); nd_set_type(node, NODE_DREGX_ONCE);
@ -3844,7 +3844,7 @@ regexp : tREGEXP_BEG xstring_contents tREGEXP_END
nd_set_type(node, NODE_DREGX); nd_set_type(node, NODE_DREGX);
} }
node->nd_cflag = options & RE_OPTION_MASK; node->nd_cflag = options & RE_OPTION_MASK;
reg_fragment_check(node->nd_lit, options); if (!NIL_P(node->nd_lit)) reg_fragment_check(node->nd_lit, options);
for (list = node->nd_next; list; list = list->nd_next) { for (list = node->nd_next; list; list = list->nd_next) {
if (nd_type(list->nd_head) == NODE_STR) { if (nd_type(list->nd_head) == NODE_STR) {
reg_fragment_check(list->nd_head->nd_lit, options); reg_fragment_check(list->nd_head->nd_lit, options);
@ -4081,7 +4081,7 @@ dsym : tSYMBEG xstring_contents tSTRING_END
nd_set_type($$, NODE_LIT); nd_set_type($$, NODE_LIT);
break; break;
default: default:
$$ = NEW_NODE(NODE_DSYM, STR_NEW0(), 1, NEW_LIST($$)); $$ = NEW_NODE(NODE_DSYM, Qnil, 1, NEW_LIST($$));
break; break;
} }
} }
@ -7809,7 +7809,7 @@ literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
htype = nd_type(head); htype = nd_type(head);
if (htype == NODE_EVSTR) { if (htype == NODE_EVSTR) {
NODE *node = NEW_DSTR(STR_NEW0()); NODE *node = NEW_DSTR(Qnil);
head = list_append(node, head); head = list_append(node, head);
} }
switch (nd_type(tail)) { switch (nd_type(tail)) {
@ -7858,7 +7858,7 @@ static NODE *
evstr2dstr_gen(struct parser_params *parser, NODE *node) evstr2dstr_gen(struct parser_params *parser, NODE *node)
{ {
if (nd_type(node) == NODE_EVSTR) { if (nd_type(node) == NODE_EVSTR) {
node = list_append(NEW_DSTR(STR_NEW0()), node); node = list_append(NEW_DSTR(Qnil), node);
} }
return node; return node;
} }

View file

@ -59,6 +59,10 @@ class TestRubyLiteral < Test::Unit::TestCase
assert_equal '16', "#{2 ** 4}" assert_equal '16', "#{2 ** 4}"
s = "string" s = "string"
assert_equal s, "#{s}" assert_equal s, "#{s}"
a = 'Foo'
b = "#{a}" << 'Bar'
assert_equal('Foo', a, 'r3842')
assert_equal('FooBar', b, 'r3842')
end end
def test_dsymbol def test_dsymbol