Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8824

Show
Ignore:
Timestamp:
02/08/08 23:35:33 (1 year ago)
Author:
nzkoz
Message:

Avoid cloning in Base#attributes. Closes #11047 [juanjo.bazan]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/base.rb

    r8806 r8824  
    22132213 
    22142214 
    2215       # Returns a hash of all the attributes with their names as keys and clones of their objects as values. 
     2215      # Returns a hash of all the attributes with their names as keys and the values of the attributes as values. 
    22162216      def attributes(options = nil) 
    2217         attributes = clone_attributes :read_attribute 
     2217        attrs = {} 
     2218        self.attribute_names.each do |name| 
     2219          attrs[name]=read_attribute(name) 
     2220        end 
    22182221 
    22192222        if options.nil? 
    2220           attribute
     2223          attr
    22212224        else 
    22222225          if except = options[:except] 
    22232226            except = Array(except).collect { |attribute| attribute.to_s } 
    2224             except.each { |attribute_name| attributes.delete(attribute_name) } 
    2225             attribute
     2227            except.each { |attribute_name| attrs.delete(attribute_name) } 
     2228            attr
    22262229          elsif only = options[:only] 
    22272230            only = Array(only).collect { |attribute| attribute.to_s } 
    2228             attributes.delete_if { |key, value| !only.include?(key) } 
    2229             attribute
     2231            attrs.delete_if { |key, value| !only.include?(key) } 
     2232            attr
    22302233          else 
    22312234            raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})"