Skip to content
Browse files

stop freezing the details hash

  • Loading branch information...
1 parent 8b85e4a commit 9d87a67590c05114d88eccd6a856d2f054860cdb @tenderlove tenderlove committed Dec 13, 2011
Showing with 1 addition and 2 deletions.
  1. +1 −2 actionpack/lib/action_view/lookup_context.rb
View
3 actionpack/lib/action_view/lookup_context.rb
@@ -56,7 +56,7 @@ class DetailsKey #:nodoc:
@details_keys = Hash.new
def self.get(details)
- @details_keys[details.freeze] ||= new
+ @details_keys[details] ||= new
end
def initialize
@@ -86,7 +86,6 @@ def disable_cache
def _set_detail(key, value)
@details_key = nil
- @details = @details.dup if @details.frozen?
@details[key] = value
end
end

4 comments on commit 9d87a67

@josevalim
Ruby on Rails member

Bro, we are freezing the hash otherwise Ruby is going to dup it internally in order to use it as key. Since _set_detail is unlikely to be called after the first template is rendered, the freeze version should perform better. amirite?

@tenderlove
Ruby on Rails member

That only applies to strings:

irb(main):001:0> x = 'hello world'
=> "hello world"
irb(main):002:0> y = {}
=> {}
irb(main):003:0> z = {}
=> {}
irb(main):004:0> z[y] = 'hi'
=> "hi"
irb(main):005:0> z.keys.first.object_id
=> 70132357527820
irb(main):006:0> y.object_id
=> 70132357527820
irb(main):007:0> z[x] = :omg
=> :omg
irb(main):008:0> z.keys.last
=> "hello world"
irb(main):009:0> z.keys.last.object_id
=> 70132353384140
irb(main):010:0> x.object_id
=> 70132353534680
irb(main):011:0>
@josevalim
Ruby on Rails member
@tenderlove
Ruby on Rails member

No problem bro! ❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️

Please sign in to comment.
Something went wrong with that request. Please try again.