mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Minor cleanup: optimize expect_id with while loop and early return\n\nResult: {"status":"keep","combined_µs":4184,"parse_µs":2921,"render_µs":1263,"allocations":25535}
This commit is contained in:
+11
-8
@@ -98,17 +98,20 @@ module Liquid
|
|||||||
# Check if next id matches expected string, consume if so. No allocation.
|
# Check if next id matches expected string, consume if so. No allocation.
|
||||||
def expect_id(expected)
|
def expect_id(expected)
|
||||||
start = @ss.pos
|
start = @ss.pos
|
||||||
if @ss.skip(ID_REGEX) == expected.bytesize
|
len = @ss.skip(ID_REGEX)
|
||||||
match = true
|
if len == expected.bytesize
|
||||||
expected.bytesize.times do |i|
|
# Compare bytes directly without allocating a string
|
||||||
if @source.getbyte(start + i) != expected.getbyte(i)
|
i = 0
|
||||||
match = false
|
while i < len
|
||||||
break
|
unless @source.getbyte(start + i) == expected.getbyte(i)
|
||||||
|
@ss.pos = start
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
i += 1
|
||||||
end
|
end
|
||||||
return true if match
|
return true
|
||||||
end
|
end
|
||||||
@ss.pos = start
|
@ss.pos = start if len
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user