Add performance rubocop and fixes

This commit is contained in:
Mike Angell
2019-08-27 22:07:44 +10:00
parent ef8a6dcda1
commit 2d0917493d
12 changed files with 20 additions and 18 deletions
+5
View File
@@ -1,5 +1,10 @@
inherit_from: inherit_from:
- .rubocop.shopify.yml - .rubocop.shopify.yml
require: rubocop-performance
Performance:
Enabled: true
Metrics/LineLength: Metrics/LineLength:
Enabled: false Enabled: false
-4
View File
@@ -21,10 +21,6 @@ matrix:
- rvm: ruby-head - rvm: ruby-head
- rvm: jruby-head - rvm: jruby-head
before_install:
- gem update --system
- gem install bundler
install: install:
- bundle install - bundle install
+1
View File
@@ -18,6 +18,7 @@ end
group :test do group :test do
gem 'rubocop', '~> 0.74.0', require: false gem 'rubocop', '~> 0.74.0', require: false
gem 'rubocop-performance', require: false
platform :mri, :truffleruby do platform :mri, :truffleruby do
gem 'liquid-c', github: 'Shopify/liquid-c', ref: '7ba926791ef8411984d0f3e41c6353fd716041c6' gem 'liquid-c', github: 'Shopify/liquid-c', ref: '7ba926791ef8411984d0f3e41c6353fd716041c6'
+2 -2
View File
@@ -65,7 +65,7 @@ module Liquid
end end
def render(context) def render(context)
render_to_output_buffer(context, ''.dup) render_to_output_buffer(context, +'')
end end
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
@@ -81,7 +81,7 @@ module Liquid
when Variable when Variable
render_node(context, output, node) render_node(context, output, node)
when Block when Block
render_node(context, node.blank? ? ''.dup : output, node) render_node(context, node.blank? ? +'' : output, node)
break if context.interrupt? # might have happened in a for-block break if context.interrupt? # might have happened in a for-block
when Continue, Break when Continue, Break
# If we get an Interrupt that means the block must stop processing. An # If we get an Interrupt that means the block must stop processing. An
+2 -2
View File
@@ -7,7 +7,7 @@ module Liquid
attr_accessor :markup_context attr_accessor :markup_context
def to_s(with_prefix = true) def to_s(with_prefix = true)
str = ''.dup str = +''
str << message_prefix if with_prefix str << message_prefix if with_prefix
str << super() str << super()
@@ -22,7 +22,7 @@ module Liquid
private private
def message_prefix def message_prefix
str = ''.dup str = +''
str << if is_a?(SyntaxError) str << if is_a?(SyntaxError)
'Liquid syntax error' 'Liquid syntax error'
else else
+1 -1
View File
@@ -70,7 +70,7 @@ module Liquid
end end
def argument def argument
str = ''.dup str = +''
# might be a keyword argument (identifier: expression) # might be a keyword argument (identifier: expression)
str << consume << consume << ' ' if look(:id) && look(:colon, 1) str << consume << consume << ' ' if look(:id) && look(:colon, 1)
+1 -1
View File
@@ -4,7 +4,7 @@ module Liquid
class Ifchanged < Block class Ifchanged < Block
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
context.stack do context.stack do
block_output = ''.dup block_output = +''
super(context, block_output) super(context, block_output)
if block_output != context.registers[:ifchanged] if block_output != context.registers[:ifchanged]
+1 -1
View File
@@ -12,7 +12,7 @@ module Liquid
end end
def parse(tokens) def parse(tokens)
@body = ''.dup @body = +''
while (token = tokens.shift) while (token = tokens.shift)
if token =~ FULL_TOKEN_POSSIBLY_INVALID if token =~ FULL_TOKEN_POSSIBLY_INVALID
@body << Regexp.last_match(1) if Regexp.last_match(1) != '' @body << Regexp.last_match(1) if Regexp.last_match(1) != ''
+1 -1
View File
@@ -204,7 +204,7 @@ module Liquid
# render the nodelist. # render the nodelist.
# for performance reasons we get an array back here. join will make a string out of it. # for performance reasons we get an array back here. join will make a string out of it.
with_profiling(context) do with_profiling(context) do
@root.render_to_output_buffer(context, output || ''.dup) @root.render_to_output_buffer(context, output || +'')
end end
rescue Liquid::MemoryError => e rescue Liquid::MemoryError => e
context.handle_error(e) context.handle_error(e)
+2 -2
View File
@@ -33,7 +33,7 @@ class ProductDrop < Liquid::Drop
class CatchallDrop < Liquid::Drop class CatchallDrop < Liquid::Drop
def liquid_method_missing(method) def liquid_method_missing(method)
'catchall_method: '.dup << method.to_s +'catchall_method: ' << method.to_s
end end
end end
@@ -50,7 +50,7 @@ class ProductDrop < Liquid::Drop
end end
def user_input def user_input
'foo'.dup.taint (+'foo').taint
end end
protected protected
+2 -2
View File
@@ -63,7 +63,7 @@ class BlockUnitTest < Minitest::Test
assert_equal 'hello', template.render assert_equal 'hello', template.render
buf = ''.dup buf = +''
output = template.render({}, output: buf) output = template.render({}, output: buf)
assert_equal 'hello', output assert_equal 'hello', output
assert_equal 'hello', buf assert_equal 'hello', buf
@@ -81,7 +81,7 @@ class BlockUnitTest < Minitest::Test
assert_equal 'foohellobar', template.render assert_equal 'foohellobar', template.render
buf = ''.dup buf = +''
output = template.render({}, output: buf) output = template.render({}, output: buf)
assert_equal 'foohellobar', output assert_equal 'foohellobar', output
assert_equal 'foohellobar', buf assert_equal 'foohellobar', buf
+2 -2
View File
@@ -33,7 +33,7 @@ class TagUnitTest < Minitest::Test
assert_equal 'hello', template.render assert_equal 'hello', template.render
buf = ''.dup buf = +''
output = template.render({}, output: buf) output = template.render({}, output: buf)
assert_equal 'hello', output assert_equal 'hello', output
assert_equal 'hello', buf assert_equal 'hello', buf
@@ -51,7 +51,7 @@ class TagUnitTest < Minitest::Test
assert_equal 'foohellobar', template.render assert_equal 'foohellobar', template.render
buf = ''.dup buf = +''
output = template.render({}, output: buf) output = template.render({}, output: buf)
assert_equal 'foohellobar', output assert_equal 'foohellobar', output
assert_equal 'foohellobar', buf assert_equal 'foohellobar', buf