From 9a41942ce163af2230a02751ea4e44013f143540 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 7 Jul 2017 23:51:20 -0300 Subject: [PATCH] Optimization on the macro expansion function --- src/macro_expansion.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/macro_expansion.cc b/src/macro_expansion.cc index cb51807c..ee4448a8 100644 --- a/src/macro_expansion.cc +++ b/src/macro_expansion.cc @@ -62,6 +62,7 @@ std::string MacroExpansion::expand(const std::string& input, while (pos != std::string::npos) { size_t start = pos; size_t end = res.find("}"); + size_t new_pos = start; if (end == std::string::npos) { return res; } @@ -313,9 +314,13 @@ std::string MacroExpansion::expand(const std::string& input, if (variableValue != NULL) { res.insert(start, *variableValue); + new_pos = new_pos + (*variableValue).length(); + } + if (new_pos + 3 >= res.length()) { + break; } - pos = res.find("%{"); + pos = res.find("%{", new_pos); } return res;