Skip to content

Commit 6828546

Browse files
Merge pull request rails#49991 from jonathanhefner/active_record-predicate_builder-avoid-nils-array
Avoid extra array allocation for `where(x: [...])`
2 parents 377f6f6 + ebd9661 commit 6828546

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

activerecord/lib/active_record/relation/predicate_builder/array_handler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def call(attribute, value)
1313
return attribute.in([]) if value.empty?
1414

1515
values = value.map { |x| x.is_a?(Base) ? x.id : x }
16-
nils = values.extract!(&:nil?)
16+
nils = values.compact!
1717
ranges = values.extract! { |v| v.is_a?(Range) }
1818

1919
values_predicate =
@@ -23,7 +23,7 @@ def call(attribute, value)
2323
else Arel::Nodes::HomogeneousIn.new(values, attribute, :in)
2424
end
2525

26-
unless nils.empty?
26+
if nils
2727
values_predicate = values_predicate.or(attribute.eq(nil))
2828
end
2929

0 commit comments

Comments
 (0)