aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-06-28 10:22:39 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-06-28 10:22:39 -0700
commit02f45d6e0ca0a3e6f5fc30b2c99bedee27484197 (patch)
tree5da2e0f8437a6f8eef0e8ab3d3734243c64c77b6 /activerecord/lib
parentc290900a77908e4ba951de405469ba21dbb6f948 (diff)
downloadrails-02f45d6e0ca0a3e6f5fc30b2c99bedee27484197.tar.gz
rails-02f45d6e0ca0a3e6f5fc30b2c99bedee27484197.tar.bz2
rails-02f45d6e0ca0a3e6f5fc30b2c99bedee27484197.zip
reduce object allocation during AR instantiation
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/base.rb2
-rw-r--r--activerecord/lib/active_record/named_scope.rb9
2 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index cba1058315..82687fce9d 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2082,6 +2082,8 @@ MSG
end
def populate_with_current_scope_attributes
+ return unless self.class.scope_attributes?
+
self.class.scope_attributes.each do |att,value|
send("#{att}=", value) if respond_to?("#{att}=")
end
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 35fb6fce03..0313abe456 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -47,15 +47,18 @@ module ActiveRecord
if current_scope
current_scope.scope_for_create
else
- # Return an empty hash in the simple case
- return {} unless default_scopes.any?
-
scope = relation.clone
scope.default_scoped = true
scope.scope_for_create
end
end
+ ##
+ # Are there default attributes associated with this scope?
+ def scope_attributes? # :nodoc:
+ current_scope || default_scopes.any?
+ end
+
# Adds a class method for retrieving and querying objects. A \scope represents a narrowing of a database query,
# such as <tt>where(:color => :red).select('shirts.*').includes(:washing_instructions)</tt>.
#