diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-29 07:37:40 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-29 07:37:40 +0000 |
commit | ed8b452e37322e66eb94dafa36f2b5da8f5ca44a (patch) | |
tree | 837ac0d60faec356052202d2724a233ad5407ed6 /compile.c | |
parent | 06b3702753c7429281323fd397e35e1c25fcc72f (diff) | |
download | ruby-ed8b452e37322e66eb94dafa36f2b5da8f5ca44a.tar.gz |
compile.c: fix performance of strconcat
* compile.c (compile_dstr_fragments): fix performance by omitting
the first empty string only for keeping literal encoding if
other literals are too. [ruby-core:70930] [Bug #11556]
* string.c (rb_str_append_literal): append but keep encoding non
US-ASCII.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -788,6 +788,12 @@ FIRST_ELEMENT(LINK_ANCHOR *anchor) } static LINK_ELEMENT * +LAST_ELEMENT(LINK_ANCHOR *anchor) +{ + return anchor->last; +} + +static LINK_ELEMENT * POP_ELEMENT(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor) { LINK_ELEMENT *elem = anchor->last; @@ -2329,6 +2335,7 @@ compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int *cntp) { NODE *list = node->nd_next; VALUE lit = node->nd_lit; + LINK_ELEMENT *first_lit = 0; int cnt = 0; debugp_param("nd_lit", lit); @@ -2337,6 +2344,7 @@ compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int *cntp) if (RB_TYPE_P(lit, T_STRING)) lit = node->nd_lit = rb_fstring(node->nd_lit); ADD_INSN1(ret, nd_line(node), putobject, lit); + if (RSTRING_LEN(lit) == 0) first_lit = LAST_ELEMENT(ret); } while (list) { @@ -2344,6 +2352,7 @@ compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int *cntp) if (nd_type(node) == NODE_STR) { node->nd_lit = rb_fstring(node->nd_lit); ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit); + lit = Qnil; } else { COMPILE(ret, "each string", node); @@ -2351,6 +2360,10 @@ compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int *cntp) cnt++; list = list->nd_next; } + if (NIL_P(lit) && first_lit) { + REMOVE_ELEM(first_lit); + --cnt; + } *cntp = cnt; return COMPILE_OK; |