drop: tiny optimization to .mutable to create fewer objects

This commit is contained in:
Parker Moore 2016-01-04 18:18:12 -08:00
parent dab53a697b
commit 9579924f8a
1 changed files with 8 additions and 3 deletions

View File

@ -15,8 +15,13 @@ module Jekyll
def self.mutable(is_mutable = nil) def self.mutable(is_mutable = nil)
if is_mutable if is_mutable
@is_mutable = is_mutable @is_mutable = is_mutable
else
@is_mutable = false
end end
@is_mutable || false end
def self.mutable?
@is_mutable
end end
# Create a new Drop # Create a new Drop
@ -39,7 +44,7 @@ module Jekyll
# #
# Returns the value for the given key, or nil if none exists # Returns the value for the given key, or nil if none exists
def [](key) def [](key)
if self.class.mutable && @mutations.key?(key) if self.class.mutable? && @mutations.key?(key)
@mutations[key] @mutations[key]
elsif respond_to? key elsif respond_to? key
public_send key public_send key
@ -65,7 +70,7 @@ module Jekyll
if respond_to?("#{key}=") if respond_to?("#{key}=")
public_send("#{key}=", val) public_send("#{key}=", val)
elsif respond_to? key elsif respond_to? key
if self.class.mutable if self.class.mutable?
@mutations[key] = val @mutations[key] = val
else else
raise Errors::DropMutationException, "Key #{key} cannot be set in the drop." raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."