mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
97819765a6
commit
cc68af3d02
1 changed files with 8 additions and 1 deletions
9
string.c
9
string.c
|
@ -4397,6 +4397,7 @@ rb_str_splice_0(VALUE str, long beg, long len, VALUE val)
|
|||
{
|
||||
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, long len, VALUE val)
|
|||
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, long len, VALUE val)
|
|||
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, long len, VALUE val)
|
|||
STR_SET_LEN(str, slen);
|
||||
TERM_FILL(&sptr[slen], TERM_LEN(str));
|
||||
OBJ_INFECT(str, val);
|
||||
ENC_CODERANGE_SET(str, cr);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue