mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-20 11:35:39 +02:00
Store tags in one big pre-allocated string and only work with refs
This should decrease the number of allocations before main is entered significantly, but complicates the code somewhat in return. Assuming I used `massif` right, doing just `SelfTest --list-tests` went from 929 allocations at "Remove gcc-4.9 from the travis builds" (2 commits up), to 614 allocations with this commit.
This commit is contained in:
@@ -38,14 +38,13 @@ namespace Catch {
|
||||
TestSpec testSpec = config.testSpec();
|
||||
std::vector<TestCaseHandle> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
||||
|
||||
std::map<std::string, TagInfo> tagCounts;
|
||||
std::map<StringRef, TagInfo> tagCounts;
|
||||
for (auto const& testCase : matchedTestCases) {
|
||||
for (auto const& tagName : testCase.getTestCaseInfo().tags) {
|
||||
std::string lcaseTagName = toLower(tagName);
|
||||
auto countIt = tagCounts.find(lcaseTagName);
|
||||
if (countIt == tagCounts.end())
|
||||
countIt = tagCounts.insert(std::make_pair(lcaseTagName, TagInfo())).first;
|
||||
countIt->second.add(tagName);
|
||||
auto it = tagCounts.find(tagName.lowerCased);
|
||||
if (it == tagCounts.end())
|
||||
it = tagCounts.insert(std::make_pair(tagName.lowerCased, TagInfo())).first;
|
||||
it->second.add(tagName.original);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,16 +70,16 @@ namespace Catch {
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
void TagInfo::add( std::string const& spelling ) {
|
||||
void TagInfo::add( StringRef spelling ) {
|
||||
++count;
|
||||
spellings.insert( spelling );
|
||||
}
|
||||
|
||||
std::string TagInfo::all() const {
|
||||
size_t size = 0;
|
||||
// 2 per tag for brackets '[' and ']'
|
||||
size_t size = spellings.size() * 2;
|
||||
for (auto const& spelling : spellings) {
|
||||
// Add 2 for the brackes
|
||||
size += spelling.size() + 2;
|
||||
size += spelling.size();
|
||||
}
|
||||
|
||||
std::string out; out.reserve(size);
|
||||
|
Reference in New Issue
Block a user