aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-09-02 10:39:29 -0600
committerSean Griffin <sean@thoughtbot.com>2015-09-02 10:40:27 -0600
commit3dd7cecfe30c425052d6414301ea1c8295c58c26 (patch)
tree7177d5d8825fa897694070d5f1030bca849b052f
parentaa3acf85cbb6bbb54c345f4cce6ab9d48d882022 (diff)
downloadrails-3dd7cecfe30c425052d6414301ea1c8295c58c26.tar.gz
rails-3dd7cecfe30c425052d6414301ea1c8295c58c26.tar.bz2
rails-3dd7cecfe30c425052d6414301ea1c8295c58c26.zip
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.
-rw-r--r--activerecord/lib/active_record/relation/merger.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index 0b38666ce9..cb971eb255 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -148,11 +148,15 @@ module ActiveRecord
end
end
+ CLAUSE_METHOD_NAMES = CLAUSE_METHODS.map do |name|
+ ["#{name}_clause", "#{name}_clause="]
+ end
+
def merge_clauses
- CLAUSE_METHODS.each do |name|
- clause = relation.send("#{name}_clause")
- other_clause = other.send("#{name}_clause")
- relation.send("#{name}_clause=", clause.merge(other_clause))
+ CLAUSE_METHOD_NAMES.each do |(reader, writer)|
+ clause = relation.send(reader)
+ other_clause = other.send(reader)
+ relation.send(writer, clause.merge(other_clause))
end
end
end