From e3ba4aa958291a71a2edacb844d82e7d9f0b7164 Mon Sep 17 00:00:00 2001 From: Tobi Lutke Date: Wed, 11 Mar 2026 10:43:20 -0400 Subject: [PATCH] =?UTF-8?q?Minor=20cleanup:=20optimize=20expect=5Fid=20wit?= =?UTF-8?q?h=20while=20loop=20and=20early=20return\n\nResult:=20{"status":?= =?UTF-8?q?"keep","combined=5F=C2=B5s":4184,"parse=5F=C2=B5s":2921,"render?= =?UTF-8?q?=5F=C2=B5s":1263,"allocations":25535}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/liquid/cursor.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/liquid/cursor.rb b/lib/liquid/cursor.rb index b0ef7aa5..b67c7a79 100644 --- a/lib/liquid/cursor.rb +++ b/lib/liquid/cursor.rb @@ -98,17 +98,20 @@ module Liquid # Check if next id matches expected string, consume if so. No allocation. def expect_id(expected) start = @ss.pos - if @ss.skip(ID_REGEX) == expected.bytesize - match = true - expected.bytesize.times do |i| - if @source.getbyte(start + i) != expected.getbyte(i) - match = false - break + len = @ss.skip(ID_REGEX) + if len == expected.bytesize + # Compare bytes directly without allocating a string + i = 0 + while i < len + unless @source.getbyte(start + i) == expected.getbyte(i) + @ss.pos = start + return false end + i += 1 end - return true if match + return true end - @ss.pos = start + @ss.pos = start if len false end