From 37a4c194052192c17c9e686925821b0fd2d7d877 Mon Sep 17 00:00:00 2001 From: Tobi Lutke Date: Wed, 11 Mar 2026 10:31:35 -0400 Subject: [PATCH] =?UTF-8?q?Skip=20find=5Findex=20when=20only=20one=20scope?= =?UTF-8?q?=20in=20find=5Fvariable=20=E2=80=94=20go=20straight=20to=20envi?= =?UTF-8?q?ronments\n\nResult:=20{"status":"keep","combined=5F=C2=B5s":432?= =?UTF-8?q?3,"parse=5F=C2=B5s":3055,"render=5F=C2=B5s":1268,"allocations":?= =?UTF-8?q?25535}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/liquid/context.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 2de41a23..f0ae8aff 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -213,9 +213,11 @@ module Liquid scope = @scopes[0] if scope.key?(key) variable = lookup_and_evaluate(scope, key, raise_on_not_found: raise_on_not_found) + elsif @scopes.length == 1 + # Only one scope and key not found — go straight to environments + variable = try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found) else - # 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 + # Multiple scopes — search through all of them index = @scopes.find_index { |s| s.key?(key) } variable = if index