ruby-changes:46270
From: nobu <ko1@a...>
Date: Mon, 17 Apr 2017 22:38:40 +0900 (JST)
Subject: [ruby-changes:46270] nobu:r58383 (trunk): string.c: improve insertion performace
nobu 2017-04-17 22:38:34 +0900 (Mon, 17 Apr 2017) New Revision: 58383 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58383 Log: string.c: improve insertion performace * string.c (rb_str_splice_0): improve performace of single byte optimizable cases, insertion 7bit string to 7bit string. [ruby-dev:49984] [Bug #13228] Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 58382) +++ string.c (revision 58383) @@ -4397,6 +4397,7 @@ rb_str_splice_0(VALUE str, long beg, lon https://github.com/ruby/ruby/blob/trunk/string.c#L4397 { char *sptr; long slen, vlen = RSTRING_LEN(val); + int cr; if (beg == 0 && vlen == 0) { rb_str_drop_bytes(str, len); @@ -4404,7 +4405,7 @@ rb_str_splice_0(VALUE str, long beg, lon https://github.com/ruby/ruby/blob/trunk/string.c#L4405 return; } - rb_str_modify(str); + str_modify_keep_cr(str); RSTRING_GETMEM(str, sptr, slen); if (len < vlen) { /* expand string */ @@ -4412,6 +4413,11 @@ rb_str_splice_0(VALUE str, long beg, lon https://github.com/ruby/ruby/blob/trunk/string.c#L4413 sptr = RSTRING_PTR(str); } + if (ENC_CODERANGE(str) == ENC_CODERANGE_7BIT) + cr = rb_enc_str_coderange(val); + else + cr = ENC_CODERANGE_UNKNOWN; + if (vlen != len) { memmove(sptr + beg + vlen, sptr + beg + len, @@ -4427,6 +4433,7 @@ rb_str_splice_0(VALUE str, long beg, lon https://github.com/ruby/ruby/blob/trunk/string.c#L4433 STR_SET_LEN(str, slen); TERM_FILL(&sptr[slen], TERM_LEN(str)); OBJ_INFECT(str, val); + ENC_CODERANGE_SET(str, cr); } void -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/