Issue #13773 has been reported by watson1978 (Shizuo Fujita).

----------------------------------------
Bug #13773: Improve String#prepend performance if only one argument is given
https://bugs.ruby-lang.org/issues/13773

* Author: watson1978 (Shizuo Fujita)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This is very similar with https://github.com/ruby/ruby/pull/1634
If only one argument is given, this will prepend the string without
generating temporary object.

~~~
String#prepend -> 47.5 % up
~~~


### Before
~~~
      String#prepend      1.517M ( 1.8%) i/s -      7.614M in   5.019819s
~~~

### After
~~~
      String#prepend      2.236M ( 3.4%) i/s -     11.234M in   5.029716s
~~~

### Test code
~~~ruby
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "String#prepend" do |loop|
    loop.times { "!".prepend("hello") }
  end
end
~~~

### Patch
https://github.com/ruby/ruby/pull/1670



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>