forked from catchorg/Catch2
Tiny speedup when listing tags
Noticed that the code was originally concatenating strings just to then append the result to another string. Now it does not create temporaries and also preallocates the string buffer.
This commit is contained in:
@ -84,9 +84,18 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string TagInfo::all() const {
|
std::string TagInfo::all() const {
|
||||||
std::string out;
|
size_t size = 0;
|
||||||
for( auto const& spelling : spellings )
|
for (auto const& spelling : spellings) {
|
||||||
out += "[" + spelling + "]";
|
// Add 2 for the brackes
|
||||||
|
size += spelling.size() + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string out; out.reserve(size);
|
||||||
|
for (auto const& spelling : spellings) {
|
||||||
|
out += '[';
|
||||||
|
out += spelling;
|
||||||
|
out += ']';
|
||||||
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user