mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 15:15:19 -07:00
more opt
This commit is contained in:
committed by
Michael Go
parent
aa45356133
commit
f42c6b0608
+22
-16
@@ -22,7 +22,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def shift
|
def shift
|
||||||
return nil if @ss.eos?
|
return if @ss.eos?
|
||||||
|
|
||||||
token = @for_liquid_tag ? next_liquid_token : next_token
|
token = @for_liquid_tag ? next_liquid_token : next_token
|
||||||
|
|
||||||
@@ -40,32 +40,35 @@ module Liquid
|
|||||||
def next_liquid_token
|
def next_liquid_token
|
||||||
# read until we find a \n
|
# read until we find a \n
|
||||||
start = @ss.pos
|
start = @ss.pos
|
||||||
if @ss.scan_until(NEWLINE).nil?
|
if @ss.skip_until(NEWLINE).nil?
|
||||||
token = @ss.rest
|
token = @ss.rest
|
||||||
@ss.terminate
|
@ss.terminate
|
||||||
return token
|
return token
|
||||||
end
|
end
|
||||||
|
|
||||||
@ss.string.byteslice(start, @ss.pos - start - 1)
|
@source.byteslice(start, @ss.pos - start - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_token
|
def next_token
|
||||||
# possible states: :text, :tag, :variable
|
# possible states: :text, :tag, :variable
|
||||||
byte_a = @ss.scan_byte
|
byte_a = @ss.peek_byte
|
||||||
|
|
||||||
if byte_a == OPEN_CURLEY
|
if byte_a == OPEN_CURLEY
|
||||||
byte_b = @ss.scan_byte
|
@ss.scan_byte
|
||||||
|
|
||||||
|
byte_b = @ss.peek_byte
|
||||||
|
|
||||||
if byte_b == PERCENTAGE
|
if byte_b == PERCENTAGE
|
||||||
|
@ss.scan_byte
|
||||||
return next_tag_token
|
return next_tag_token
|
||||||
elsif byte_b == OPEN_CURLEY
|
elsif byte_b == OPEN_CURLEY
|
||||||
|
@ss.scan_byte
|
||||||
return next_variable_token
|
return next_variable_token
|
||||||
end
|
end
|
||||||
|
|
||||||
@ss.pos -= 1
|
@ss.pos -= 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ss.pos -= 1
|
|
||||||
next_text_token
|
next_text_token
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -78,8 +81,8 @@ module Liquid
|
|||||||
return token
|
return token
|
||||||
end
|
end
|
||||||
|
|
||||||
@ss.pos -= 2
|
pos = @ss.pos -= 2
|
||||||
@source.byteslice(start, @ss.pos - start)
|
@source.byteslice(start, pos - start)
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_variable_token
|
def next_variable_token
|
||||||
@@ -89,9 +92,9 @@ module Liquid
|
|||||||
byte_a = @ss.scan_byte
|
byte_a = @ss.scan_byte
|
||||||
|
|
||||||
until @ss.eos?
|
until @ss.eos?
|
||||||
byte_a = @ss.scan_byte while @ss.eos? == false && byte_a != CLOSE_CURLEY && byte_a != OPEN_CURLEY
|
byte_a = @ss.scan_byte while byte_a && byte_a != CLOSE_CURLEY && byte_a != OPEN_CURLEY
|
||||||
|
|
||||||
break if @ss.eos?
|
break unless byte_a
|
||||||
|
|
||||||
byte_b = @ss.scan_byte
|
byte_b = @ss.scan_byte
|
||||||
|
|
||||||
@@ -101,20 +104,23 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
if byte_a == CLOSE_CURLEY && byte_b == CLOSE_CURLEY
|
if byte_a == CLOSE_CURLEY && byte_b == CLOSE_CURLEY
|
||||||
return @ss.string.byteslice(start, @ss.pos - start)
|
return @source.byteslice(start, @ss.pos - start)
|
||||||
elsif byte_a == OPEN_CURLEY && byte_b == PERCENTAGE
|
elsif byte_a == OPEN_CURLEY && byte_b == PERCENTAGE
|
||||||
return next_tag_token(start)
|
return next_tag_token_with_start(start)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
"{{"
|
"{{"
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_tag_token(start = nil)
|
def next_tag_token
|
||||||
start ||= @ss.pos - 2
|
start = @ss.pos - 2
|
||||||
|
len = @ss.skip_until(TAG_END) || 0
|
||||||
@ss.scan_until(TAG_END)
|
@source.byteslice(start, len + 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
def next_tag_token_with_start(start)
|
||||||
|
@ss.skip_until(TAG_END)
|
||||||
@source.byteslice(start, @ss.pos - start)
|
@source.byteslice(start, @ss.pos - start)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ Benchmark.ips do |x|
|
|||||||
puts "Running benchmark for #{x.time} seconds (with #{x.warmup} seconds warmup)."
|
puts "Running benchmark for #{x.time} seconds (with #{x.warmup} seconds warmup)."
|
||||||
puts
|
puts
|
||||||
|
|
||||||
x.report("parse:") { profiler.compile }
|
phase = ENV["PHASE"] || "all"
|
||||||
# x.report("render:") { profiler.render }
|
|
||||||
# x.report("parse & render:") { profiler.run }
|
x.report("tokenize:") { profiler.tokenize } if phase == "all" || phase == "tokenize"
|
||||||
|
x.report("parse:") { profiler.compile } if phase == "all" || phase == "parse"
|
||||||
|
x.report("render:") { profiler.render } if phase == "all" || phase == "render"
|
||||||
|
x.report("parse & render:") { profiler.run } if phase == "all" || phase == "run"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ class ThemeRunner
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# `tokenize` will just test the tokenizen portion of liquid without any templates
|
||||||
|
def tokenize
|
||||||
|
@tests.each do |test_hash|
|
||||||
|
tokenizer = Liquid::Tokenizer.new(test_hash[:liquid], true)
|
||||||
|
while tokenizer.shift; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# `run` is called to benchmark rendering and compiling at the same time
|
# `run` is called to benchmark rendering and compiling at the same time
|
||||||
def run
|
def run
|
||||||
each_test do |liquid, layout, assigns, page_template, template_name|
|
each_test do |liquid, layout, assigns, page_template, template_name|
|
||||||
|
|||||||
Reference in New Issue
Block a user