Avoid #fetch for non-nil values.

This is purely a performance optimisation.

See https://gist.github.com/3552829
This commit is contained in:
Jon Leighton 2012-08-31 17:04:36 +01:00
parent 86c3dfbd47
commit 85098e4b31
1 changed files with 2 additions and 1 deletions

View File

@ -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) {