mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
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:
parent
3701c2e2e6
commit
cf55cfd76f
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user