summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-25 11:14:40 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-25 11:14:40 +0000
commit592c3f9b10a9c2b2249fa4c6e1dc2146b3666e4b (patch)
tree3496e8da1f1af32a5aa63176a8f582c1262f9c07 /string.c
parent4bc4403b2db8d166965faeeb1379418296ecbe27 (diff)
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
Diffstat (limited to 'string.c')
-rw-r--r--string.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/string.c b/string.c
index 54a89f3565..7c70b0a4c6 100644
--- a/string.c
+++ b/string.c
@@ -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);