diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-07 23:59:55 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-07 23:59:55 -0300 |
commit | 9bf772d936c3236267eb8f7a09dde21226125234 (patch) | |
tree | da99f09577ad01b6290d7774ec75ab960b7cdb58 /activerecord | |
parent | a11571cec3213753d63ac3e6b4bb3b97fe2594a6 (diff) | |
parent | 607a4482f0988571d8f0ce52a3d4db9b371d2b41 (diff) | |
download | rails-9bf772d936c3236267eb8f7a09dde21226125234.tar.gz rails-9bf772d936c3236267eb8f7a09dde21226125234.tar.bz2 rails-9bf772d936c3236267eb8f7a09dde21226125234.zip |
Merge pull request #21537 from tgxworld/perf_reduce_allocation
PERF: Reduce allocation in `resolve_column_aliases`.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/table_metadata.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/table_metadata.rb b/activerecord/lib/active_record/table_metadata.rb index 702bf8a885..f9bb1cf5e0 100644 --- a/activerecord/lib/active_record/table_metadata.rb +++ b/activerecord/lib/active_record/table_metadata.rb @@ -12,13 +12,13 @@ module ActiveRecord def resolve_column_aliases(hash) # This method is a hot spot, so for now, use Hash[] to dup the hash. # https://bugs.ruby-lang.org/issues/7166 - hash = Hash[hash] - hash.keys.grep(Symbol) do |key| - if klass.attribute_alias? key - hash[klass.attribute_alias(key)] = hash.delete key + new_hash = Hash[hash] + hash.each do |key, _| + if (key.is_a?(Symbol)) && klass.attribute_alias?(key) + new_hash[klass.attribute_alias(key)] = new_hash.delete(key) end end - hash + new_hash end def arel_attribute(column_name) |