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:
Martin Hořeňovský
2019-11-14 10:53:12 +01:00
parent 302e2c0b06
commit d36c15c3ca
18 changed files with 296 additions and 187 deletions
+6 -22
View File
@@ -116,26 +116,9 @@ namespace Catch {
TestSpec::Matches m_matches;
};
void applyFilenamesAsTags(Catch::IConfig const& config) {
for (auto const& testCase : getAllTestCasesSorted(config)) {
// Yeah, sue me. This will be removed soon.
auto& testInfo = const_cast<TestCaseInfo&>(testCase.getTestCaseInfo());
std::string filename = testInfo.lineInfo.file;
auto lastSlash = filename.find_last_of("\\/");
if (lastSlash != std::string::npos) {
filename.erase(0, lastSlash);
filename[0] = '#';
}
auto lastDot = filename.find_last_of('.');
if (lastDot != std::string::npos) {
filename.erase(lastDot);
}
auto tags = testInfo.tags;
tags.push_back(std::move(filename));
setTags(testInfo, tags);
void applyFilenamesAsTags() {
for (auto const& testInfo : getRegistryHub().getTestCaseRegistry().getAllInfos()) {
testInfo->addFilenameTag();
}
}
@@ -285,8 +268,9 @@ namespace Catch {
seedRng( *m_config );
if( m_configData.filenamesAsTags )
applyFilenamesAsTags( *m_config );
if (m_configData.filenamesAsTags) {
applyFilenamesAsTags();
}
// Create reporter(s) so we can route listings through them
auto reporter = makeReporter(m_config);