mirror of
https://github.com/kemko/liquid.git
synced 2026-01-06 18:25:41 +03:00
Merge pull request #385 from Shopify/optimize_scope_variable_resolution
Remove block in favour of for loop to reduce temporary object allocation during variable context resolution
This commit is contained in:
@@ -194,7 +194,12 @@ module Liquid
|
|||||||
|
|
||||||
# Fetches an object starting at the local scope and then moving up the hierachy
|
# Fetches an object starting at the local scope and then moving up the hierachy
|
||||||
def find_variable(key)
|
def find_variable(key)
|
||||||
scope = @scopes.find { |s| s.has_key?(key) }
|
|
||||||
|
# This was changed from find() to find_index() because this is a very hot
|
||||||
|
# path and find_index() is optimized in MRI to reduce object allocation
|
||||||
|
index = @scopes.find_index { |s| s.has_key?(key) }
|
||||||
|
scope = @scopes[index] if index
|
||||||
|
|
||||||
variable = nil
|
variable = nil
|
||||||
|
|
||||||
if scope.nil?
|
if scope.nil?
|
||||||
|
|||||||
Reference in New Issue
Block a user