Make vector operations more efficient

stage/master/nightly/2022/12/14
Rose 2022-12-10 12:48:09 -05:00
parent 192903b244
commit 6d15754814
9 changed files with 12 additions and 11 deletions

View File

@ -73,6 +73,7 @@ public:
bool StartProcess()
{
std::vector<const char*> args;
args.reserve(this->CommandLineStrings.size());
for (std::string const& cl : this->CommandLineStrings) {
args.push_back(cl.c_str());
}

View File

@ -518,9 +518,7 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
PresetPair<ConfigurePreset> presetPair;
presetPair.Unexpanded = preset;
presetPair.Expanded = cm::nullopt;
if (!this->ConfigurePresets
.emplace(std::make_pair(preset.Name, presetPair))
.second) {
if (!this->ConfigurePresets.emplace(preset.Name, presetPair).second) {
return ReadFileResult::DUPLICATE_PRESETS;
}

View File

@ -448,6 +448,7 @@ class Target
JBTs<T> ToJBTs(BTs<T> const& bts)
{
std::vector<JBTIndex> ids;
ids.reserve(bts.Backtraces.size());
for (cmListFileBacktrace const& backtrace : bts.Backtraces) {
ids.emplace_back(this->Backtraces.Add(backtrace));
}

View File

@ -15,7 +15,7 @@ cmFileLockPool::~cmFileLockPool() = default;
void cmFileLockPool::PushFunctionScope()
{
this->FunctionScopes.push_back(ScopePool());
this->FunctionScopes.emplace_back();
}
void cmFileLockPool::PopFunctionScope()
@ -26,7 +26,7 @@ void cmFileLockPool::PopFunctionScope()
void cmFileLockPool::PushFileScope()
{
this->FileScopes.push_back(ScopePool());
this->FileScopes.emplace_back();
}
void cmFileLockPool::PopFileScope()

View File

@ -2098,6 +2098,7 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
}
std::vector<std::string> byproducts;
byproducts.reserve(this->CrossConfigs.size());
for (auto const& config : this->CrossConfigs) {
byproducts.push_back(
this->BuildAlias(GetByproductsForCleanTargetName(), config));

View File

@ -3623,7 +3623,7 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
}
// Add a pair of config and item to target-item map
auto& itemVector = targetItemMap[libName];
itemVector.emplace_back(ConfigItemPair(configName, &libItem));
itemVector.emplace_back(configName, &libItem);
// Add product file-name to a lib-product map
auto productName =
cmSystemTools::GetFilenameName(libItem.Value.Value);
@ -4381,7 +4381,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
cmXCodeObject* config =
this->CreateObject(cmXCodeObject::XCBuildConfiguration);
config->AddAttribute("name", this->CreateString(name));
configs.push_back(std::make_pair(name, config));
configs.emplace_back(name, config);
}
if (defaultConfigName.empty()) {
defaultConfigName = "Debug";

View File

@ -970,8 +970,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
uiHeader, uiHeaderGenex, cmStrCat(this->Dir.Build, "/include"_s),
uiHeaderFilePath);
this->Uic.UiHeaders.emplace_back(
std::make_pair(uiHeader, uiHeaderGenex));
this->Uic.UiHeaders.emplace_back(uiHeader, uiHeaderGenex);
} else {
// Register skipped .ui file
this->Uic.SkipUi.insert(fullPath);

View File

@ -2661,9 +2661,9 @@ cmFileSet* cmTarget::GetFileSet(const std::string& name)
std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet(
const std::string& name, const std::string& type, cmFileSetVisibility vis)
{
auto result = this->impl->FileSets.emplace(std::make_pair(
auto result = this->impl->FileSets.emplace(
name,
cmFileSet(*this->GetMakefile()->GetCMakeInstance(), name, type, vis)));
cmFileSet(*this->GetMakefile()->GetCMakeInstance(), name, type, vis));
if (result.second) {
auto bt = this->impl->Makefile->GetBacktrace();
if (type == this->impl->HeadersFileSets.TypeName) {

View File

@ -241,6 +241,7 @@ bool cmUVProcessChain::InternalData::AddCommand(
options.file = config.Arguments[0].c_str();
std::vector<const char*> arguments;
arguments.reserve(config.Arguments.size());
for (auto const& arg : config.Arguments) {
arguments.push_back(arg.c_str());
}