From cd1724bddeac5dd4c01ab0a2d527110fff9cf5f9 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 8 Sep 2022 12:43:03 +0200 Subject: [PATCH] rb_str_concat_literals: use rb_str_buf_append That's about 1.30x faster. --- benchmark/string_concat.yml | 10 ++++++++++ string.c | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/benchmark/string_concat.yml b/benchmark/string_concat.yml index b8a69ed909..e65c00cca9 100644 --- a/benchmark/string_concat.yml +++ b/benchmark/string_concat.yml @@ -33,3 +33,13 @@ benchmark: buffer << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK buffer << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK buffer << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK << UCHUNK + interpolation: | + buffer = "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \ + "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \ + "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \ + "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \ + "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \ + "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \ + "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \ + "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \ + "#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" diff --git a/string.c b/string.c index a2bc7410fa..963652cdb9 100644 --- a/string.c +++ b/string.c @@ -3393,8 +3393,7 @@ rb_str_concat_literals(size_t num, const VALUE *strary) const VALUE v = strary[i]; int encidx = ENCODING_GET(v); - rb_enc_cr_str_buf_cat(str, RSTRING_PTR(v), RSTRING_LEN(v), - encidx, ENC_CODERANGE(v), NULL); + rb_str_buf_append(str, v); if (encidx != ENCINDEX_US_ASCII) { if (ENCODING_GET_INLINED(str) == ENCINDEX_US_ASCII) rb_enc_set_index(str, encidx);