Skip to content

Commit 6e14feb

Browse files
committed
use array arithmetic rather than create sets
1 parent 37b67df commit 6e14feb

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

activerecord/lib/active_record/associations/association_collection.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,10 @@ def replace(other_array)
344344
other_array.each { |val| raise_on_type_mismatch(val) }
345345

346346
load_target
347-
other = other_array.size < 100 ? other_array : other_array.to_set
348-
current = @target.size < 100 ? @target : @target.to_set
349347

350348
transaction do
351-
delete(@target.select { |v| !other.include?(v) })
352-
concat(other_array.select { |v| !current.include?(v) })
349+
delete(@target - other_array)
350+
concat(other_array - @target)
353351
end
354352
end
355353

0 commit comments

Comments
 (0)