diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-02-06 10:36:01 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-02-06 10:39:12 -0700 |
commit | 9c47b874d112414df7f80f9ed852adb48ba6d268 (patch) | |
tree | b3062d4eac0a9f273941a4cf0eb6e539013f455b /activesupport/lib | |
parent | de9313ce7c310adc75f4bb22e2fab125b538e620 (diff) | |
download | rails-9c47b874d112414df7f80f9ed852adb48ba6d268.tar.gz rails-9c47b874d112414df7f80f9ed852adb48ba6d268.tar.bz2 rails-9c47b874d112414df7f80f9ed852adb48ba6d268.zip |
Improve the performance of HWIDA `select` and `reject`
These are (potentially, depending on input) called in several places in
both the router, and Active Record. The code also becomes much cleaner.
This results in ~33% performance gain in both methods.
Calculating -------------------------------------
before 15.696k i/100ms
after 19.865k i/100ms
-------------------------------------------------
before 303.064k (± 2.6%) i/s - 1.523M
after 446.734k (± 2.4%) i/s - 2.245M
On Ruby 2.2, a warning will be emitted about states not being copied,
because we're calling `super` from a subclass. We can safely ignore it,
however, since we're converting the result back into a HWIDA
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 4f71f13971..c7477b9ff4 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -237,12 +237,12 @@ module ActiveSupport def deep_symbolize_keys; to_hash.deep_symbolize_keys! end def to_options!; self end - def select(*args, &block) - dup.tap { |hash| hash.select!(*args, &block) } + def select(*) + super.with_indifferent_access end - def reject(*args, &block) - dup.tap { |hash| hash.reject!(*args, &block) } + def reject(*) + super.with_indifferent_access end # Convert to a regular hash with string keys. |