From 8750b4b006fb56e90154a12b2cb0442260be8caf Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Fri, 30 Aug 2019 09:01:47 +0530 Subject: [PATCH] Reduce allocations from `Liquid::Context.new` --- lib/liquid/context.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 1b15ca7eb..90e6b7899 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -21,8 +21,10 @@ def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: end def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil, static_registers = {}, static_environments = {}) - @environments = [environments].flatten - @static_environments = [static_environments].flatten.map(&:freeze).freeze + @environments = [environments] + @environments.flatten! + + @static_environments = [static_environments].flat_map(&:freeze).freeze @scopes = [(outer_scope || {})] @registers = registers @static_registers = static_registers.freeze