aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2015-08-17 18:44:51 -0400
committerJean Boussier <jean.boussier@gmail.com>2015-08-17 18:44:51 -0400
commita94c2e1f23c4216a5b854c13f439882311fda461 (patch)
tree6ff7cb788d4686e29901ded66678e86b81e06629
parent8d7b883f33034732996f80f73f46d050c7dc9210 (diff)
downloadrails-a94c2e1f23c4216a5b854c13f439882311fda461.tar.gz
rails-a94c2e1f23c4216a5b854c13f439882311fda461.tar.bz2
rails-a94c2e1f23c4216a5b854c13f439882311fda461.zip
Use == 0 instead of .zero? in #try
The perf gain is relatively minor but consistent: ``` Calculating ------------------------------------- 0.zero? 137.091k i/100ms 1.zero? 137.350k i/100ms 0 == 0 142.207k i/100ms 1 == 0 144.724k i/100ms ------------------------------------------------- 0.zero? 8.893M (± 6.5%) i/s - 44.280M 1.zero? 8.751M (± 6.4%) i/s - 43.677M 0 == 0 10.033M (± 7.0%) i/s - 49.915M 1 == 0 9.814M (± 8.0%) i/s - 48.772M ``` And try! is quite a big hotspot for us so every little gain is appreciable.
-rw-r--r--activesupport/lib/active_support/core_ext/object/try.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb
index 69be6c4abc..c67eb25b68 100644
--- a/activesupport/lib/active_support/core_ext/object/try.rb
+++ b/activesupport/lib/active_support/core_ext/object/try.rb
@@ -8,7 +8,7 @@ module ActiveSupport
def try!(*a, &b)
if a.empty? && block_given?
- if b.arity.zero?
+ if b.arity == 0
instance_eval(&b)
else
yield self