mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 09:20:42 -07:00
Introduce the AST Optimizer
... that can only optimize one thing: combine `| append: 'a' | append: 'b'` into a single `| append_all: ['a', 'b']` filter call. This avoids all the intermediate allocations caused by several `append`. Also introduce a new filter `append_all: [*items]`.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class OptimizerUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_combines_append_filters
|
||||
optimizer = Optimizer.new
|
||||
var = Variable.new('hello | append: "a" | append: b', ParseContext.new)
|
||||
var = optimizer.optimize(var)
|
||||
assert_equal([
|
||||
['append_all', ["a", VariableLookup.new("b")]]
|
||||
], var.filters)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user