From aebba01f437d864baf7165f19737440002016413 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sat, 31 Jan 2015 17:28:04 -0700 Subject: Remove `AttributeSet#initialized_keys` This method doesn't need to be lazy, as it is never called from reads. The only time it is called are in write cases, where we're about to loop through the results of it, and build the attribute objects anyway. So we don't gain anything by dodging the instantiation here. This is the only method that coupled `AttributeSet` to `LazyAttributeHash`, so removing it puts us back in a place where we can use a normal hash instead. --- activerecord/lib/active_record/attribute_set.rb | 2 +- activerecord/lib/active_record/attribute_set/builder.rb | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb index fdce68ce45..0c9793d470 100644 --- a/activerecord/lib/active_record/attribute_set.rb +++ b/activerecord/lib/active_record/attribute_set.rb @@ -24,7 +24,7 @@ module ActiveRecord end def keys - attributes.initialized_keys + attributes.each_key.select { |name| self[name].initialized? } end def fetch_value(name) diff --git a/activerecord/lib/active_record/attribute_set/builder.rb b/activerecord/lib/active_record/attribute_set/builder.rb index 3a76f5262d..0f3c285a80 100644 --- a/activerecord/lib/active_record/attribute_set/builder.rb +++ b/activerecord/lib/active_record/attribute_set/builder.rb @@ -20,7 +20,7 @@ module ActiveRecord end class LazyAttributeHash # :nodoc: - delegate :select, :transform_values, to: :materialize + delegate :select, :transform_values, :each_key, to: :materialize def initialize(types, values, additional_types) @types = types @@ -45,10 +45,6 @@ module ActiveRecord delegate_hash[key] = value end - def initialized_keys - delegate_hash.keys | values.keys - end - def initialize_dup(_) @delegate_hash = delegate_hash.transform_values(&:dup) super -- cgit v1.2.3