diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-05-14 03:43:09 -0300 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-05-14 03:43:09 -0300 |
commit | 4046ac7e88dfcd9089e602ad0d6196bc8efc46a6 (patch) | |
tree | 985f3758a2d60bc695ee00109621b2f17d3ea05d /activesupport/lib | |
parent | b981369ab60472fbb63896906137b7008fe05ca7 (diff) | |
parent | 6751b1032070a3b26e89a151cbe564a354eb580d (diff) | |
download | rails-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.rb | 4 |
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 |