Skip to content

Commit d8c0504

Browse files
committed
Avoid creating new Array object per each comparison
Benchmark.ips do |x| arr = [:js] x.report('==') { arr == [:js] } x.report('length') { (arr.length == 0) && (arr[0] == :js) } x.report('one?') { arr.one? && (arr[0] == :js) } x.compare! end Warming up -------------------------------------- == 731.426k i/100ms length 1.967M i/100ms one? 1.440M i/100ms Calculating ------------------------------------- == 7.291M (± 0.8%) i/s - 36.571M in 5.016130s length 19.633M (± 0.8%) i/s - 98.356M in 5.010104s one? 14.387M (± 0.8%) i/s - 71.998M in 5.004721s Comparison: length: 19632843.5 i/s one?: 14386784.0 i/s - 1.36x (± 0.00) slower ==: 7291274.5 i/s - 2.69x (± 0.00) slower
1 parent bdd090a commit d8c0504

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

actionview/lib/action_view/lookup_context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def formats=(values)
267267
raise ArgumentError, "Invalid formats: #{invalid_values.map(&:inspect).join(", ")}"
268268
end
269269

270-
if values == [:js]
270+
if (values.length == 1) && (values[0] == :js)
271271
values << :html
272272
@html_fallback_for_js = true
273273
end

0 commit comments

Comments
 (0)