Project: Use emplace_back where applicable in lockAndRead()

Same behavior, but allows for in-place construction.
This commit is contained in:
Lioncash 2020-04-05 09:12:25 -04:00
parent 45556184b4
commit ede801b344
1 changed files with 12 additions and 9 deletions

View File

@ -60,24 +60,27 @@ std::vector<std::string>& Project::ConfigFile::lockAndRead() {
mainString += std::string(readBuf, readSz);
}
std::string::const_iterator begin = mainString.begin();
std::string::const_iterator end = mainString.begin();
auto begin = mainString.cbegin();
auto end = mainString.cbegin();
m_lines.clear();
while (end != mainString.end()) {
std::string::const_iterator origEnd = end;
if (*end == '\0')
auto origEnd = end;
if (*end == '\0') {
break;
else if (CheckNewLineAdvance(end)) {
if (begin != origEnd)
m_lines.push_back(std::string(begin, origEnd));
}
if (CheckNewLineAdvance(end)) {
if (begin != origEnd) {
m_lines.emplace_back(begin, origEnd);
}
begin = end;
continue;
}
++end;
}
if (begin != end)
m_lines.push_back(std::string(begin, end));
if (begin != end) {
m_lines.emplace_back(begin, end);
}
return m_lines;
}