aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-05-14 03:43:09 -0300
committerRafael França <rafaelmfranca@gmail.com>2016-05-14 03:43:09 -0300
commit4046ac7e88dfcd9089e602ad0d6196bc8efc46a6 (patch)
tree985f3758a2d60bc695ee00109621b2f17d3ea05d /activesupport/lib
parentb981369ab60472fbb63896906137b7008fe05ca7 (diff)
parent6751b1032070a3b26e89a151cbe564a354eb580d (diff)
downloadrails-4046ac7e88dfcd9089e602ad0d6196bc8efc46a6.tar.gz
rails-4046ac7e88dfcd9089e602ad0d6196bc8efc46a6.tar.bz2
rails-4046ac7e88dfcd9089e602ad0d6196bc8efc46a6.zip
Merge pull request #25008 from lvl0nax/as_enumarable_index_by_refactoring
Perfomance fix for ActiveSupport Enumerable#index_by
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index 9a893157ea..8ebe758078 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -34,7 +34,9 @@ module Enumerable
# => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}
def index_by
if block_given?
- Hash[map { |elem| [yield(elem), elem] }]
+ result = {}
+ each { |elem| result[yield(elem)] = elem }
+ result
else
to_enum(:index_by) { size if respond_to?(:size) }
end