From 808c3711d096cd4255070fe953a6f96790be9df9 Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Wed, 19 Mar 2025 02:20:02 +0100 Subject: [PATCH] Removes unnecessary template content copy (#301) By taking the template content by value and moving into the local member, we can prevent and additional copy of 'content' when creating a Template. --- include/inja/parser.hpp | 2 +- include/inja/template.hpp | 2 +- single_include/inja/inja.hpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/inja/parser.hpp b/include/inja/parser.hpp index bfc5d6f..a8b6a28 100644 --- a/include/inja/parser.hpp +++ b/include/inja/parser.hpp @@ -625,7 +625,7 @@ public: : config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {} Template parse(std::string_view input, std::string_view path) { - auto result = Template(static_cast(input)); + auto result = Template(std::string(input)); parse_into(result, path); return result; } diff --git a/include/inja/template.hpp b/include/inja/template.hpp index 30638e8..be60f54 100644 --- a/include/inja/template.hpp +++ b/include/inja/template.hpp @@ -19,7 +19,7 @@ struct Template { std::map> block_storage; explicit Template() {} - explicit Template(const std::string& content): content(content) {} + explicit Template(std::string content): content(std::move(content)) {} /// Return number of variables (total number, not distinct ones) in the template int count_variables() const { diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index 7ea810c..22c27f2 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -824,7 +824,7 @@ struct Template { std::map> block_storage; explicit Template() {} - explicit Template(const std::string& content): content(content) {} + explicit Template(std::string content): content(std::move(content)) {} /// Return number of variables (total number, not distinct ones) in the template int count_variables() const { @@ -2068,7 +2068,7 @@ public: : config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {} Template parse(std::string_view input, std::string_view path) { - auto result = Template(static_cast(input)); + auto result = Template(std::string(input)); parse_into(result, path); return result; }