Skip to content

Commit ebd9661

Browse files
Avoid extra array allocation for where(x: [...])
We do not need to construct an array of `nil`s; we merely need to determine whether any are present in the values array and remove them. Thus, we can use `compact!` instead of `extract!`.
1 parent 377f6f6 commit ebd9661

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)