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); mainString += std::string(readBuf, readSz);
} }
std::string::const_iterator begin = mainString.begin(); auto begin = mainString.cbegin();
std::string::const_iterator end = mainString.begin(); auto end = mainString.cbegin();
m_lines.clear(); m_lines.clear();
while (end != mainString.end()) { while (end != mainString.end()) {
std::string::const_iterator origEnd = end; auto origEnd = end;
if (*end == '\0') if (*end == '\0') {
break; break;
else if (CheckNewLineAdvance(end)) { }
if (begin != origEnd) if (CheckNewLineAdvance(end)) {
m_lines.push_back(std::string(begin, origEnd)); if (begin != origEnd) {
m_lines.emplace_back(begin, origEnd);
}
begin = end; begin = end;
continue; continue;
} }
++end; ++end;
} }
if (begin != end) if (begin != end) {
m_lines.push_back(std::string(begin, end)); m_lines.emplace_back(begin, end);
}
return m_lines; return m_lines;
} }