mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Fast return for primitive types in find_variable — skip to_liquid and respond_to?(:context=)\n\nResult: {"status":"keep","combined_µs":4225,"parse_µs":3009,"render_µs":1216,"allocations":25535}
This commit is contained in:
@@ -228,18 +228,20 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
# update variable's context before invoking #to_liquid
|
# update variable's context before invoking #to_liquid
|
||||||
# Fast path: skip respond_to? check for common primitive types
|
# Fast path: primitive types don't need context= or to_liquid conversion
|
||||||
unless variable.instance_of?(String) || variable.instance_of?(Integer) || variable.instance_of?(Float) ||
|
case variable
|
||||||
variable.instance_of?(NilClass) || variable.instance_of?(TrueClass) || variable.instance_of?(FalseClass)
|
when String, Integer, Float, NilClass, TrueClass, FalseClass
|
||||||
variable.context = self if variable.respond_to?(:context=)
|
return variable
|
||||||
|
when Array, Hash, Time
|
||||||
|
return variable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
variable.context = self if variable.respond_to?(:context=)
|
||||||
|
|
||||||
liquid_variable = variable.to_liquid
|
liquid_variable = variable.to_liquid
|
||||||
|
|
||||||
if variable != liquid_variable
|
if variable != liquid_variable
|
||||||
unless liquid_variable.instance_of?(String) || liquid_variable.instance_of?(Integer)
|
liquid_variable.context = self if liquid_variable.respond_to?(:context=)
|
||||||
liquid_variable.context = self if liquid_variable.respond_to?(:context=)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
liquid_variable
|
liquid_variable
|
||||||
|
|||||||
Reference in New Issue
Block a user