mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Fast-path Hash lookups in VariableLookup#evaluate — skip respond_to? checks for Hash objects\n\nResult: {"status":"keep","combined_µs":4110,"parse_µs":2922,"render_µs":1188,"allocations":25535}
This commit is contained in:
@@ -177,9 +177,10 @@ module Liquid
|
|||||||
|
|
||||||
# If object is a hash- or array-like object we look for the
|
# If object is a hash- or array-like object we look for the
|
||||||
# presence of the key and if its available we return it
|
# presence of the key and if its available we return it
|
||||||
if object.respond_to?(:[]) &&
|
if object.instance_of?(Hash) ? object.key?(key) :
|
||||||
((object.respond_to?(:key?) && object.key?(key)) ||
|
(object.respond_to?(:[]) &&
|
||||||
(object.respond_to?(:fetch) && key.is_a?(Integer)))
|
((object.respond_to?(:key?) && object.key?(key)) ||
|
||||||
|
(object.respond_to?(:fetch) && key.is_a?(Integer))))
|
||||||
|
|
||||||
# if its a proc we will replace the entry with the proc
|
# if its a proc we will replace the entry with the proc
|
||||||
object = context.lookup_and_evaluate(object, key)
|
object = context.lookup_and_evaluate(object, key)
|
||||||
|
|||||||
Reference in New Issue
Block a user