mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
153d7ca630
commit
e38e0c61e9
1 changed files with 1 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue