aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-11-18 12:31:23 -0800
committerSean Griffin <sean@thoughtbot.com>2014-11-18 12:32:10 -0800
commitedc39ff756d09b746bdc1acb8d814c3148289846 (patch)
tree62b8cf24d406b0c6a4ae299e4395db3269462621 /activerecord
parent3ecc5d30eb0901f4e3c4d3bca1957f633a6a695b (diff)
downloadrails-edc39ff756d09b746bdc1acb8d814c3148289846.tar.gz
rails-edc39ff756d09b746bdc1acb8d814c3148289846.tar.bz2
rails-edc39ff756d09b746bdc1acb8d814c3148289846.zip
Remove needless call to `key?` when building attributes
This appears to be a performance hotspot, see #17655.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_set/builder.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_set/builder.rb b/activerecord/lib/active_record/attribute_set/builder.rb
index fd134a304b..05138ae36d 100644
--- a/activerecord/lib/active_record/attribute_set/builder.rb
+++ b/activerecord/lib/active_record/attribute_set/builder.rb
@@ -62,9 +62,11 @@ module ActiveRecord
def assign_default_value(name)
type = additional_types.fetch(name, types[name])
+ value_present = true
+ value = values.fetch(name) { value_present = false }
- if values.key?(name)
- delegate_hash[name] = Attribute.from_database(name, values[name], type)
+ if value_present
+ delegate_hash[name] = Attribute.from_database(name, value, type)
elsif types.key?(name)
delegate_hash[name] = Attribute.uninitialized(name, type)
end