aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-03-14 14:17:59 -0700
committerwycats <wycats@gmail.com>2010-03-14 17:29:25 -0600
commit95bd56e3cc028971059ac4ec0dfe3e29012ef35d (patch)
tree6b2d0098339fbae54458c3d66c58f4b329293328 /activerecord/lib
parent115230e6195115d6200047eb0c3247d3aad82ee7 (diff)
downloadrails-95bd56e3cc028971059ac4ec0dfe3e29012ef35d.tar.gz
rails-95bd56e3cc028971059ac4ec0dfe3e29012ef35d.tar.bz2
rails-95bd56e3cc028971059ac4ec0dfe3e29012ef35d.zip
speeding up clone_attributes, changing readonly to be initialized in def initialize
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/base.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 9ec7c1ecaf..0ce876d7a9 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1507,6 +1507,7 @@ module ActiveRecord #:nodoc:
@attributes = attributes_from_column_definition
@attributes_cache = {}
@new_record = true
+ @readonly = false
ensure_proper_type
if scope = self.class.send(:current_scoped_methods)
@@ -1571,7 +1572,7 @@ module ActiveRecord #:nodoc:
# user_path(user) # => "/users/Phusion"
def to_param
# We can't use alias_method here, because method 'id' optimizes itself on the fly.
- (id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes
+ id && id.to_s # Be sure to stringify the id for routes
end
# Returns a cache key that can be used to identify this record.
@@ -1696,7 +1697,7 @@ module ActiveRecord #:nodoc:
# This is especially useful for boolean flags on existing records. The regular +update_attribute+ method
# in Base is replaced with this when the validations module is mixed in, which it is by default.
def update_attribute(name, value)
- send(name.to_s + '=', value)
+ send("#{name}=", value)
save(:validate => false)
end
@@ -1913,14 +1914,14 @@ module ActiveRecord #:nodoc:
# Returns duplicated record with unfreezed attributes.
def dup
obj = super
- obj.instance_variable_set('@attributes', instance_variable_get('@attributes').dup)
+ obj.instance_variable_set('@attributes', @attributes.dup)
obj
end
# Returns +true+ if the record is read only. Records loaded through joins with piggy-back
# attributes will be marked as read only since they cannot be saved.
def readonly?
- defined?(@readonly) && @readonly == true
+ @readonly
end
# Marks this record as read only.
@@ -1940,10 +1941,10 @@ module ActiveRecord #:nodoc:
protected
def clone_attributes(reader_method = :read_attribute, attributes = {})
- self.attribute_names.inject(attributes) do |attrs, name|
- attrs[name] = clone_attribute_value(reader_method, name)
- attrs
+ attribute_names.each do |name|
+ attributes[name] = clone_attribute_value(reader_method, name)
end
+ attributes
end
def clone_attribute_value(reader_method, attribute_name)
@@ -2246,4 +2247,4 @@ end
# TODO: Remove this and make it work with LAZY flag
require 'active_record/connection_adapters/abstract_adapter'
-ActiveRecord.run_base_hooks(ActiveRecord::Base) \ No newline at end of file
+ActiveRecord.run_base_hooks(ActiveRecord::Base)