mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
avoid allocating seen={} hash in Utils.to_s/inspect when not needed
This commit is contained in:
+6
-6
@@ -96,7 +96,7 @@ module Liquid
|
|||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.to_s(obj, seen = {})
|
def self.to_s(obj, seen = nil)
|
||||||
case obj
|
case obj
|
||||||
when BigDecimal
|
when BigDecimal
|
||||||
obj.to_s("F")
|
obj.to_s("F")
|
||||||
@@ -105,30 +105,30 @@ module Liquid
|
|||||||
# custom implementation. Otherwise we use Liquid's default
|
# custom implementation. Otherwise we use Liquid's default
|
||||||
# implementation.
|
# implementation.
|
||||||
if obj.class.instance_method(:to_s) == HASH_TO_S_METHOD
|
if obj.class.instance_method(:to_s) == HASH_TO_S_METHOD
|
||||||
hash_inspect(obj, seen)
|
hash_inspect(obj, seen || {})
|
||||||
else
|
else
|
||||||
obj.to_s
|
obj.to_s
|
||||||
end
|
end
|
||||||
when Array
|
when Array
|
||||||
array_inspect(obj, seen)
|
array_inspect(obj, seen || {})
|
||||||
else
|
else
|
||||||
obj.to_s
|
obj.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.inspect(obj, seen = {})
|
def self.inspect(obj, seen = nil)
|
||||||
case obj
|
case obj
|
||||||
when Hash
|
when Hash
|
||||||
# If the custom hash implementation overrides `#inspect`, use their
|
# If the custom hash implementation overrides `#inspect`, use their
|
||||||
# custom implementation. Otherwise we use Liquid's default
|
# custom implementation. Otherwise we use Liquid's default
|
||||||
# implementation.
|
# implementation.
|
||||||
if obj.class.instance_method(:inspect) == HASH_INSPECT_METHOD
|
if obj.class.instance_method(:inspect) == HASH_INSPECT_METHOD
|
||||||
hash_inspect(obj, seen)
|
hash_inspect(obj, seen || {})
|
||||||
else
|
else
|
||||||
obj.inspect
|
obj.inspect
|
||||||
end
|
end
|
||||||
when Array
|
when Array
|
||||||
array_inspect(obj, seen)
|
array_inspect(obj, seen || {})
|
||||||
else
|
else
|
||||||
obj.inspect
|
obj.inspect
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user