From ec74a77240115bf129f5a585648bf955c9cb79da Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Fri, 3 Nov 2023 14:29:36 -0500 Subject: [PATCH] prepend string to avoid a small allocation --- lib/view_component/compiler.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/view_component/compiler.rb b/lib/view_component/compiler.rb index 6aa13617c..1cc258dff 100644 --- a/lib/view_component/compiler.rb +++ b/lib/view_component/compiler.rb @@ -55,7 +55,7 @@ def call SOURCE # rubocop:disable Style/EvalWithLocation if frozen_string_literal - component_class.class_eval("# frozen_string_literal: true\n#{source}", template.path, template.lineno - 1) + component_class.class_eval(source.prepend("# frozen_string_literal: true\n"), template.path, template.lineno - 1) else component_class.class_eval(source, template.path, template.lineno) end @@ -83,7 +83,7 @@ def #{method_name} SOURCE # rubocop:disable Style/EvalWithLocation if frozen_string_literal - component_class.class_eval("# frozen_string_literal: true\n#{source}", template[:path], -1) + component_class.class_eval(source.prepend("# frozen_string_literal: true\n"), template[:path], -1) else component_class.class_eval(source, template[:path], 0) end