diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-08-31 17:04:36 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-08-31 17:15:22 +0100 |
commit | 85098e4b31263b04200cb9ac8406c9b2a38cce35 (patch) | |
tree | d14132a6a1fceaabd4a5e67c1fa6d7b16e06e85c | |
parent | 86c3dfbd47cb96af02daaa655963292b1a1b110e (diff) | |
download | rails-85098e4b31263b04200cb9ac8406c9b2a38cce35.tar.gz rails-85098e4b31263b04200cb9ac8406c9b2a38cce35.tar.bz2 rails-85098e4b31263b04200cb9ac8406c9b2a38cce35.zip |
Avoid #fetch for non-nil values.
This is purely a performance optimisation.
See https://gist.github.com/3552829
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/read.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 0e36d73dcc..1a4cb25dd7 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -72,7 +72,8 @@ module ActiveRecord name_sym = attr_name.to_sym # If it's cached, just return it - @attributes_cache.fetch(name_sym) { + # We use #[] first as a perf optimization for non-nil values. See https://gist.github.com/3552829. + @attributes_cache[name_sym] || @attributes_cache.fetch(name_sym) { name = attr_name.to_s column = @columns_hash.fetch(name) { |