[*] Don't realloc and copy old str in SplitNewlines; use last index

This commit is contained in:
Reece Wilson 2021-06-27 23:19:30 +01:00
parent 337062b490
commit 4f399b7e01

View File

@ -11,13 +11,12 @@ namespace Aurora::Parse
{
static void SplitNewlines(const AuString &in, std::function<void(const AuString &)> 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));
}
}