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.
This commit is contained in:
Florian Sattler
2025-03-19 02:20:02 +01:00
committed by GitHub
parent 9416142a50
commit 808c3711d0
3 changed files with 4 additions and 4 deletions

View File

@@ -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<std::string>(input));
auto result = Template(std::string(input));
parse_into(result, path);
return result;
}

View File

@@ -19,7 +19,7 @@ struct Template {
std::map<std::string, std::shared_ptr<BlockStatementNode>> 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 {

View File

@@ -824,7 +824,7 @@ struct Template {
std::map<std::string, std::shared_ptr<BlockStatementNode>> 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<std::string>(input));
auto result = Template(std::string(input));
parse_into(result, path);
return result;
}