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
This commit is contained in:
parent
06b3702753
commit
ed8b452e37
@ -1,3 +1,12 @@
|
|||||||
|
Tue Sep 29 16:37:29 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Mon Sep 28 17:40:17 2015 Shugo Maeda <shugo@ruby-lang.org>
|
Mon Sep 28 17:40:17 2015 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* lib/net/ftp.rb (mtime): use usec instead of fractions to parse
|
* lib/net/ftp.rb (mtime): use usec instead of fractions to parse
|
||||||
|
13
compile.c
13
compile.c
@ -787,6 +787,12 @@ FIRST_ELEMENT(LINK_ANCHOR *anchor)
|
|||||||
return anchor->anchor.next;
|
return anchor->anchor.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static LINK_ELEMENT *
|
||||||
|
LAST_ELEMENT(LINK_ANCHOR *anchor)
|
||||||
|
{
|
||||||
|
return anchor->last;
|
||||||
|
}
|
||||||
|
|
||||||
static LINK_ELEMENT *
|
static LINK_ELEMENT *
|
||||||
POP_ELEMENT(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor)
|
POP_ELEMENT(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor)
|
||||||
{
|
{
|
||||||
@ -2329,6 +2335,7 @@ 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;
|
||||||
|
LINK_ELEMENT *first_lit = 0;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
debugp_param("nd_lit", lit);
|
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))
|
if (RB_TYPE_P(lit, T_STRING))
|
||||||
lit = node->nd_lit = rb_fstring(node->nd_lit);
|
lit = node->nd_lit = rb_fstring(node->nd_lit);
|
||||||
ADD_INSN1(ret, nd_line(node), putobject, lit);
|
ADD_INSN1(ret, nd_line(node), putobject, lit);
|
||||||
|
if (RSTRING_LEN(lit) == 0) first_lit = LAST_ELEMENT(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (list) {
|
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) {
|
if (nd_type(node) == NODE_STR) {
|
||||||
node->nd_lit = rb_fstring(node->nd_lit);
|
node->nd_lit = rb_fstring(node->nd_lit);
|
||||||
ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit);
|
ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit);
|
||||||
|
lit = Qnil;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
COMPILE(ret, "each string", node);
|
COMPILE(ret, "each string", node);
|
||||||
@ -2351,6 +2360,10 @@ compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int *cntp)
|
|||||||
cnt++;
|
cnt++;
|
||||||
list = list->nd_next;
|
list = list->nd_next;
|
||||||
}
|
}
|
||||||
|
if (NIL_P(lit) && first_lit) {
|
||||||
|
REMOVE_ELEM(first_lit);
|
||||||
|
--cnt;
|
||||||
|
}
|
||||||
*cntp = cnt;
|
*cntp = cnt;
|
||||||
|
|
||||||
return COMPILE_OK;
|
return COMPILE_OK;
|
||||||
|
@ -370,7 +370,7 @@ concatstrings
|
|||||||
val = rb_str_resurrect(TOPN(i));
|
val = rb_str_resurrect(TOPN(i));
|
||||||
while (i-- > 0) {
|
while (i-- > 0) {
|
||||||
const VALUE v = TOPN(i);
|
const VALUE v = TOPN(i);
|
||||||
rb_str_append(val, v);
|
rb_str_append_literal(val, v);
|
||||||
}
|
}
|
||||||
POPN(num);
|
POPN(num);
|
||||||
}
|
}
|
||||||
|
12
string.c
12
string.c
@ -2460,6 +2460,18 @@ rb_str_append(VALUE str, VALUE str2)
|
|||||||
return rb_str_buf_append(str, str2);
|
return rb_str_buf_append(str, str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_str_append_literal(VALUE str, VALUE str2)
|
||||||
|
{
|
||||||
|
int encidx = rb_enc_get_index(str2);
|
||||||
|
rb_str_buf_append(str, str2);
|
||||||
|
if (encidx != ENCINDEX_US_ASCII) {
|
||||||
|
if (rb_enc_get_index(str) == ENCINDEX_US_ASCII)
|
||||||
|
rb_enc_associate_index(str, encidx);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* str << integer -> str
|
* str << integer -> str
|
||||||
|
Loading…
x
Reference in New Issue
Block a user