mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Skip respond_to?(:context=) for primitive types in find_variable — avoids method lookup overhead\n\nResult: {"status":"keep","combined_µs":4207,"parse_µs":2943,"render_µs":1264,"allocations":25535}
This commit is contained in:
@@ -226,11 +226,19 @@ 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
|
||||||
|
unless variable.instance_of?(String) || variable.instance_of?(Integer) || variable.instance_of?(Float) ||
|
||||||
|
variable.instance_of?(NilClass) || variable.instance_of?(TrueClass) || variable.instance_of?(FalseClass)
|
||||||
variable.context = self if variable.respond_to?(:context=)
|
variable.context = self if variable.respond_to?(:context=)
|
||||||
|
end
|
||||||
|
|
||||||
liquid_variable = variable.to_liquid
|
liquid_variable = variable.to_liquid
|
||||||
|
|
||||||
liquid_variable.context = self if variable != liquid_variable && liquid_variable.respond_to?(:context=)
|
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=)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
liquid_variable
|
liquid_variable
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user