1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Avoid extra Array allocation

This commit is contained in:
Ryuta Kamizono 2020-01-16 07:00:51 +09:00
parent ac206e6dff
commit c900cdfdc3

View file

@ -48,18 +48,18 @@ module ActiveRecord
raw_records = owner_keys.empty? ? [] : records_for(owner_keys) raw_records = owner_keys.empty? ? [] : records_for(owner_keys)
@preloaded_records = raw_records.select do |record| @preloaded_records = raw_records.select do |record|
assignments = [] assignments = false
owners_by_key[convert_key(record[association_key_name])].each do |owner| owners_by_key[convert_key(record[association_key_name])].each do |owner|
entries = (@records_by_owner[owner] ||= []) entries = (@records_by_owner[owner] ||= [])
if reflection.collection? || entries.empty? if reflection.collection? || entries.empty?
entries << record entries << record
assignments << record assignments = true
end end
end end
!assignments.empty? assignments
end end
end end