Skip to content

Commit 2983bf9

Browse files
committed
[GR-23791] Add Liquid benchmarks
PullRequest: truffleruby/2053
2 parents d7043a7 + 7c82be6 commit 2983bf9

File tree

114 files changed

+8124
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+8124
-1
lines changed

bench/liquid/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2005, 2006 Tobias Luetke
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bench/liquid/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Benchmarks from [Liquid](https://github.com/Shopify/liquid around), imported around version 4.0.3.
2+
3+
The code is imported from revision `e9b649b3455c63859f1b865a8684607d6ff5b050`.
4+
5+
Imported:
6+
* `LICENSE`
7+
* `lib/`
8+
* `performance/`
9+
10+
The imported files are under the MIT license, see `LICENSE`.

bench/liquid/lib/liquid.rb

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2005 Tobias Luetke
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining
6+
# a copy of this software and associated documentation files (the
7+
# "Software"), to deal in the Software without restriction, including
8+
# without limitation the rights to use, copy, modify, merge, publish,
9+
# distribute, sublicense, and/or sell copies of the Software, and to
10+
# permit persons to whom the Software is furnished to do so, subject to
11+
# the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be
14+
# included in all copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
module Liquid
25+
FilterSeparator = /\|/
26+
ArgumentSeparator = ','
27+
FilterArgumentSeparator = ':'
28+
VariableAttributeSeparator = '.'
29+
WhitespaceControl = '-'
30+
TagStart = /\{\%/
31+
TagEnd = /\%\}/
32+
VariableSignature = /\(?[\w\-\.\[\]]\)?/
33+
VariableSegment = /[\w\-]/
34+
VariableStart = /\{\{/
35+
VariableEnd = /\}\}/
36+
VariableIncompleteEnd = /\}\}?/
37+
QuotedString = /"[^"]*"|'[^']*'/
38+
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
39+
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
40+
AnyStartingTag = /#{TagStart}|#{VariableStart}/o
41+
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
42+
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
43+
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
44+
45+
singleton_class.send(:attr_accessor, :cache_classes)
46+
self.cache_classes = true
47+
end
48+
49+
require "liquid/version"
50+
require 'liquid/parse_tree_visitor'
51+
require 'liquid/lexer'
52+
require 'liquid/parser'
53+
require 'liquid/i18n'
54+
require 'liquid/drop'
55+
require 'liquid/tablerowloop_drop'
56+
require 'liquid/forloop_drop'
57+
require 'liquid/extensions'
58+
require 'liquid/errors'
59+
require 'liquid/interrupts'
60+
require 'liquid/strainer_factory'
61+
require 'liquid/strainer_template'
62+
require 'liquid/expression'
63+
require 'liquid/context'
64+
require 'liquid/parser_switching'
65+
require 'liquid/tag'
66+
require 'liquid/block'
67+
require 'liquid/block_body'
68+
require 'liquid/document'
69+
require 'liquid/variable'
70+
require 'liquid/variable_lookup'
71+
require 'liquid/range_lookup'
72+
require 'liquid/file_system'
73+
require 'liquid/resource_limits'
74+
require 'liquid/template'
75+
require 'liquid/standardfilters'
76+
require 'liquid/condition'
77+
require 'liquid/utils'
78+
require 'liquid/tokenizer'
79+
require 'liquid/parse_context'
80+
require 'liquid/partial_cache'
81+
require 'liquid/usage'
82+
require 'liquid/register'
83+
require 'liquid/static_registers'
84+
require 'liquid/template_factory'
85+
86+
# Load all the tags of the standard library
87+
#
88+
Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f }
89+
Dir["#{__dir__}/liquid/registers/*.rb"].each { |f| require f }

bench/liquid/lib/liquid/block.rb

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# frozen_string_literal: true
2+
3+
module Liquid
4+
class Block < Tag
5+
MAX_DEPTH = 100
6+
7+
def initialize(tag_name, markup, options)
8+
super
9+
@blank = true
10+
end
11+
12+
def parse(tokens)
13+
@body = BlockBody.new
14+
while parse_body(@body, tokens)
15+
end
16+
end
17+
18+
# For backwards compatibility
19+
def render(context)
20+
@body.render(context)
21+
end
22+
23+
def blank?
24+
@blank
25+
end
26+
27+
def nodelist
28+
@body.nodelist
29+
end
30+
31+
def unknown_tag(tag, _params, _tokens)
32+
if tag == 'else'
33+
raise SyntaxError, parse_context.locale.t("errors.syntax.unexpected_else",
34+
block_name: block_name)
35+
elsif tag.start_with?('end')
36+
raise SyntaxError, parse_context.locale.t("errors.syntax.invalid_delimiter",
37+
tag: tag,
38+
block_name: block_name,
39+
block_delimiter: block_delimiter)
40+
else
41+
raise SyntaxError, parse_context.locale.t("errors.syntax.unknown_tag", tag: tag)
42+
end
43+
end
44+
45+
def block_name
46+
@tag_name
47+
end
48+
49+
def block_delimiter
50+
@block_delimiter ||= "end#{block_name}"
51+
end
52+
53+
protected
54+
55+
def parse_body(body, tokens)
56+
if parse_context.depth >= MAX_DEPTH
57+
raise StackLevelError, "Nesting too deep"
58+
end
59+
parse_context.depth += 1
60+
begin
61+
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
62+
@blank &&= body.blank?
63+
64+
return false if end_tag_name == block_delimiter
65+
unless end_tag_name
66+
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_never_closed", block_name: block_name)
67+
end
68+
69+
# this tag is not registered with the system
70+
# pass it to the current block for special handling or error reporting
71+
unknown_tag(end_tag_name, end_tag_params, tokens)
72+
end
73+
ensure
74+
parse_context.depth -= 1
75+
end
76+
77+
true
78+
end
79+
end
80+
end

0 commit comments

Comments
 (0)