str_buf_cat: preserve coderange when going through fastpath
rb_str_modify clear the coderange, which in this case isn't necessary. ``` compare-ruby: ruby 3.2.0dev (2022-07-12T15:01:11Z master 71aec68566) [arm64-darwin21] built-ruby: ruby 3.2.0dev (2022-07-19T07:17:01Z faster-buffer-conc.. 3cad62aab4) [arm64-darwin21] warming up... | |compare-ruby|built-ruby| |:---------------------|-----------:|---------:| |binary_concat_utf8 | 360.617k| 605.091k| | | -| 1.68x| |binary_concat_binary | 446.650k| 605.053k| | | -| 1.35x| |utf8_concat_utf8 | 454.166k| 597.311k| | | -| 1.32x| ``` ``` | |compare-ruby|built-ruby| |:-----------|-----------:|---------:| |erb_render | 1.790M| 2.045M| | | -| 1.14x| ```
This commit is contained in:
parent
0ae8dbbee0
commit
cb9fd920a3
Notes:
git
2022-07-19 17:42:07 +09:00
18
string.c
18
string.c
@ -3110,8 +3110,16 @@ rb_str_resize(VALUE str, long len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
str_buf_cat(VALUE str, const char *ptr, long len)
|
str_buf_cat4(VALUE str, const char *ptr, long len, bool keep_cr)
|
||||||
{
|
{
|
||||||
|
if (keep_cr) {
|
||||||
|
str_modify_keep_cr(str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_str_modify(str);
|
||||||
|
}
|
||||||
|
if (len == 0) return 0;
|
||||||
|
|
||||||
long capa, total, olen, off = -1;
|
long capa, total, olen, off = -1;
|
||||||
char *sptr;
|
char *sptr;
|
||||||
const int termlen = TERM_LEN(str);
|
const int termlen = TERM_LEN(str);
|
||||||
@ -3123,8 +3131,7 @@ str_buf_cat(VALUE str, const char *ptr, long len)
|
|||||||
if (ptr >= sptr && ptr <= sptr + olen) {
|
if (ptr >= sptr && ptr <= sptr + olen) {
|
||||||
off = ptr - sptr;
|
off = ptr - sptr;
|
||||||
}
|
}
|
||||||
rb_str_modify(str);
|
|
||||||
if (len == 0) return 0;
|
|
||||||
if (STR_EMBED_P(str)) {
|
if (STR_EMBED_P(str)) {
|
||||||
capa = str_embed_capa(str) - termlen;
|
capa = str_embed_capa(str) - termlen;
|
||||||
sptr = RSTRING(str)->as.embed.ary;
|
sptr = RSTRING(str)->as.embed.ary;
|
||||||
@ -3159,7 +3166,8 @@ str_buf_cat(VALUE str, const char *ptr, long len)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define str_buf_cat2(str, ptr) str_buf_cat((str), (ptr), rb_strlen_lit(ptr))
|
#define str_buf_cat(str, ptr, len) str_buf_cat4((str), (ptr), len, false)
|
||||||
|
#define str_buf_cat2(str, ptr) str_buf_cat4((str), (ptr), rb_strlen_lit(ptr), false)
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_str_cat(VALUE str, const char *ptr, long len)
|
rb_str_cat(VALUE str, const char *ptr, long len)
|
||||||
@ -3322,7 +3330,7 @@ rb_str_buf_append(VALUE str, VALUE str2)
|
|||||||
{
|
{
|
||||||
int str2_cr = rb_enc_str_coderange(str2);
|
int str2_cr = rb_enc_str_coderange(str2);
|
||||||
if (str2_cr == ENC_CODERANGE_7BIT && str_enc_fastpath(str)) {
|
if (str2_cr == ENC_CODERANGE_7BIT && str_enc_fastpath(str)) {
|
||||||
str_buf_cat(str, RSTRING_PTR(str2), RSTRING_LEN(str2));
|
str_buf_cat4(str, RSTRING_PTR(str2), RSTRING_LEN(str2), true);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user