[ruby-cvs:67661] watson1978:r60480 (trunk): string.c: Improve String#prepend performance if only one argument is given

watson1978 at ruby-lang.org watson1978 at ruby-lang.org
Fri Oct 27 23:55:03 JST 2017


watson1978	2017-10-27 23:55:03 +0900 (Fri, 27 Oct 2017)

  New Revision: 60480

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60480

  Log:
    string.c: Improve String#prepend performance if only one argument is given
    
    * string.c (rb_str_prepend_multi): Prepend the string without generating
        temporary String object if only one argument is given.
    This is very similar with https://github.com/ruby/ruby/pull/1634
    
    String#prepend -> 47.5 % up
    
        [Fix GH-1670] [ruby-core:82195] [Bug #13773]
    
    * Before
          String#prepend      1.517M (?\194?\177 1.8%) i/s -      7.614M in   5.019819s
    
    * After
          String#prepend      2.236M (?\194?\177 3.4%) i/s -     11.234M in   5.029716s
    
    * Test code
    require 'benchmark/ips'
    
    Benchmark.ips do |x|
      x.report "String#prepend" do |loop|
        loop.times { "!".prepend("hello") }
      end
    end

  Modified files:
    trunk/string.c


More information about the ruby-cvs mailing list