Skip to content

Commit 3dd7cec

Browse files
committed
Don't allocate a bunch of strings in Relation::Merger
Since the strings are dynamically computed from a constant, the actual strings we're creating are a known set. We can compute them ahead of time, and reduce the number of allocations in that method.
1 parent aa3acf8 commit 3dd7cec

File tree

1 file changed

+8
-4
lines changed
  • activerecord/lib/active_record/relation

1 file changed

+8
-4
lines changed

activerecord/lib/active_record/relation/merger.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,15 @@ def merge_single_values
148148
end
149149
end
150150

151+
CLAUSE_METHOD_NAMES = CLAUSE_METHODS.map do |name|
152+
["#{name}_clause", "#{name}_clause="]
153+
end
154+
151155
def merge_clauses
152-
CLAUSE_METHODS.each do |name|
153-
clause = relation.send("#{name}_clause")
154-
other_clause = other.send("#{name}_clause")
155-
relation.send("#{name}_clause=", clause.merge(other_clause))
156+
CLAUSE_METHOD_NAMES.each do |(reader, writer)|
157+
clause = relation.send(reader)
158+
other_clause = other.send(reader)
159+
relation.send(writer, clause.merge(other_clause))
156160
end
157161
end
158162
end

0 commit comments

Comments
 (0)