1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

string.c: Optimize String#concat when argc is 1

Optimize performance regression introduced in r56021.

* Benchmark (i7-4790K @ 4.00GH, x86_64 GNU/Linux)

Benchmark.ips do |x|
  x.report("String#concat (1)") { "a".concat("b") }
  if RUBY_VERSION >= "2.4.0"
    x.report("String#concat (2)") { "a".concat("b", "c") }
  end
end

* Ruby 2.3

Calculating -------------------------------------
   String#concat (1)      6.003M (± 5.2%) i/s -     30.122M in   5.031646s

* Ruby 2.4 (Before this patch)

Calculating -------------------------------------
   String#concat (1)      4.458M (± 8.9%) i/s -     22.298M in   5.058084s
   String#concat (2)      3.660M (± 5.6%) i/s -     18.314M in   5.020527s

* Ruby 2.4 (After this patch)

Calculating -------------------------------------
   String#concat (1)      6.448M (± 5.2%) i/s -     32.215M in   5.010833s
   String#concat (2)      3.633M (± 9.0%) i/s -     18.056M in   5.022603s

[fix GH-1631]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
k0kubun 2017-05-25 11:14:40 +00:00
parent 4bc4403b2d
commit 592c3f9b10

View file

@ -2935,7 +2935,9 @@ rb_str_concat_multi(int argc, VALUE *argv, VALUE str)
{
str_modifiable(str);
if (argc > 0) {
if (argc == 1) {
return rb_str_concat(str, argv[0]);
} else if (argc > 1) {
int i;
VALUE arg_str = rb_str_tmp_new(0);
rb_enc_copy(arg_str, str);