aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-11-15 15:26:15 -0600
committerSean Griffin <sean@seantheprogrammer.com>2015-11-15 15:26:15 -0600
commite38e0c61e9d73b3531a02c6dd44c9694f64f2c0a (patch)
treeff97ae309f0b67b920680973dcd0d95c190b4e3c /activerecord
parent153d7ca630d10449f24f5576f27452f9efb40791 (diff)
downloadrails-e38e0c61e9d73b3531a02c6dd44c9694f64f2c0a.tar.gz
rails-e38e0c61e9d73b3531a02c6dd44c9694f64f2c0a.tar.bz2
rails-e38e0c61e9d73b3531a02c6dd44c9694f64f2c0a.zip
Freeze association foreign keys to reduce allocations
The string returned here will ultimately get used as a key of a hash in the attribute set once the attributes are being built. When you give a non-frozen string to `Hash#[]`, it will be duped. Be freezing we can significantly reduce the number of times we end up allocating `"user_id"` This does not include any additional tests, as this should not have any public facing implications. If you are mutating the result of `Reflection#foreign_key`, please stop.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/reflection.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 5b9d45d871..a549b28f16 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -371,7 +371,7 @@ module ActiveRecord
end
def foreign_key
- @foreign_key ||= options[:foreign_key] || derive_foreign_key
+ @foreign_key ||= options[:foreign_key] || derive_foreign_key.freeze
end
def association_foreign_key