aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-09-07 23:59:55 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-09-07 23:59:55 -0300
commit9bf772d936c3236267eb8f7a09dde21226125234 (patch)
treeda99f09577ad01b6290d7774ec75ab960b7cdb58
parenta11571cec3213753d63ac3e6b4bb3b97fe2594a6 (diff)
parent607a4482f0988571d8f0ce52a3d4db9b371d2b41 (diff)
downloadrails-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`.
-rw-r--r--activerecord/lib/active_record/table_metadata.rb10
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)