From 8d21a9dae9a57134181b247bbbd02aae763bbaf0 Mon Sep 17 00:00:00 2001 From: pantor Date: Mon, 2 Apr 2018 15:43:32 +0200 Subject: [PATCH] multiple render optimizations --- src/inja.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/inja.hpp b/src/inja.hpp index 57a233b..d6981c8 100644 --- a/src/inja.hpp +++ b/src/inja.hpp @@ -145,7 +145,7 @@ inline MatchType search(const std::string& input, const std::map& r // Map to vectors std::vector class_vector; std::vector regexes_vector; - for (const auto element: regexes) { + for (const auto& element: regexes) { class_vector.push_back(element.first); regexes_vector.push_back(element.second); } @@ -210,7 +210,7 @@ inline MatchClosed search_closed(const std::string& input, const Regex& regex_st template inline MatchType match(const std::string& input, const std::map& regexes) { MatchType match; - for (const auto e : regexes) { + for (const auto& e: regexes) { if (std::regex_match(input.cbegin(), input.cend(), match, e.second)) { match.set_type(e.first); match.set_regex(e.second); @@ -517,7 +517,7 @@ public: std::string render(Template temp, const json& data) { std::string result = ""; - for (auto element: temp.parsed_template.children) { + for (const auto& element: temp.parsed_template.children) { switch (element->type) { case Parsed::Type::String: { auto element_string = std::static_pointer_cast(element); @@ -562,7 +562,7 @@ public: } case Parsed::Loop::ForMapIn: { const std::map map = eval_expression>(element_loop->list, data); - for (auto const& item : map) { + for (const auto& item: map) { json data_loop = data; data_loop[element_loop->key] = item.first; data_loop[element_loop->value] = item.second; @@ -576,7 +576,7 @@ public: } case Parsed::Type::Condition: { auto element_condition = std::static_pointer_cast(element); - for (auto branch: element_condition->children) { + for (const auto& branch: element_condition->children) { auto element_branch = std::static_pointer_cast(branch); if (element_branch->condition_type == Parsed::Condition::Else || eval_expression(element_branch->condition, data)) { result.append( render(Template(*element_branch), data) ); @@ -844,7 +844,7 @@ public: case Parsed::Statement::Include: { std::string included_filename = path + match_statement.str(1); Template included_template = parse_template(included_filename); - for (auto element : included_template.parsed_template.children) { + for (auto& element: included_template.parsed_template.children) { result.emplace_back(element); } break;