Store the profiler in the context instead of a thread-local variable (#1364)

This commit is contained in:
Dylan Thacker-Smith
2020-12-09 10:04:20 -05:00
committed by GitHub
parent 7361220af6
commit 60214b957c
3 changed files with 33 additions and 26 deletions
+8 -6
View File
@@ -106,9 +106,13 @@ module Liquid
# Parse source code.
# Returns self for easy chaining
def parse(source, options = {})
if (profiling = options[:profile])
raise "Profiler not loaded, require 'liquid/profiler' first" unless defined?(Liquid::Profiler)
end
@options = options
@profiling = options[:profile]
@line_numbers = options[:line_numbers] || @profiling
@profiling = profiling
@line_numbers = options[:line_numbers] || profiling
parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options)
@root = Document.parse(tokenize(source), parse_context)
@warnings = parse_context.warnings
@@ -217,10 +221,8 @@ module Liquid
end
def with_profiling(context)
if @profiling && !context.partial
raise "Profiler not loaded, require 'liquid/profiler' first" unless defined?(Liquid::Profiler)
@profiler = Profiler.new
if @profiling && context.profiler.nil?
@profiler = context.profiler = Profiler.new
@profiler.start
begin