String#* takes one argument, and in that case, better not splat the arg
because splatting the argument allocates an extra Array object. benchmark ```ruby s = 'a'.html_safe Benchmark.ips do |x| x.report('') { s * 1 } end ``` result ``` before Warming up -------------------------------------- 216.816k i/100ms Calculating ------------------------------------- 2.341M (± 2.0%) i/s - 11.708M in 5.002555s after Warming up -------------------------------------- 315.118k i/100ms Calculating ------------------------------------- 3.704M (± 1.5%) i/s - 18.592M in 5.020261s ```
This commit is contained in:
parent
62ca4b5621
commit
5653d7d56d
@ -100,7 +100,7 @@ def +(other)
|
||||
dup.concat(other)
|
||||
end
|
||||
|
||||
def *(*)
|
||||
def *(_)
|
||||
new_string = super
|
||||
new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
|
||||
new_safe_buffer.instance_variable_set(:@html_safe, @html_safe)
|
||||
|
Loading…
Reference in New Issue
Block a user