Permalink
Browse files

Freeze columns only once per Result

  • Loading branch information...
1 parent 883fa8f commit da400fbb0ba6a130237d17cdd58c860be02294ad @spastorino spastorino committed Sep 20, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 activerecord/lib/active_record/result.rb
@@ -53,12 +53,15 @@ def initialize_copy(other)
private
def hash_rows
- @hash_rows ||= @rows.map { |row|
- # We freeze the strings to prevent them getting duped when
- # used as keys in ActiveRecord::Model's @attributes hash
- columns = @columns.map { |c| c.freeze }
- Hash[columns.zip(row)]
- }
+ @hash_rows ||=
+ begin
+ # We freeze the strings to prevent them getting duped when
+ # used as keys in ActiveRecord::Model's @attributes hash
+ columns = @columns.map { |c| c.dup.freeze }
+ @rows.map { |row|
+ Hash[columns.zip(row)]
+ }
+ end
end
end
end

2 comments on commit da400fb

Hey @spastorino why are you doing dup here? You do freeze because of string memory efficiency (probably?). Thx!

Owner

spastorino replied Dec 10, 2016

Hey I do not remember, please do investigate about it, thanks :).

Please sign in to comment.