From 4f399b7e0178a440cfc871e64433e57d27befe77 Mon Sep 17 00:00:00 2001 From: Reece Date: Sun, 27 Jun 2021 23:19:30 +0100 Subject: [PATCH] [*] Don't realloc and copy old str in SplitNewlines; use last index --- Include/Aurora/Parse/LineParser.hpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Include/Aurora/Parse/LineParser.hpp b/Include/Aurora/Parse/LineParser.hpp index d6bee763..780d7731 100644 --- a/Include/Aurora/Parse/LineParser.hpp +++ b/Include/Aurora/Parse/LineParser.hpp @@ -11,13 +11,12 @@ namespace Aurora::Parse { static void SplitNewlines(const AuString &in, std::function lineCallback) { - AuMach index = 0; - AuString cpy = in; + AuMach index = 0, startIdx = 0; - while ((index = cpy.find("\n")) != AuString::npos) + while ((index = in.find("\n"), startIdx) != AuString::npos) { - auto line = cpy.substr(0, index); - cpy = cpy.substr(index + 1); + auto line = in.substr(0, index); + startIdx = index + 1; if (line[line.size() - 1] == '\r') { @@ -27,6 +26,6 @@ namespace Aurora::Parse lineCallback(line); } - lineCallback(cpy); + lineCallback(in.substr(startIdx)); } } \ No newline at end of file