From f9599ed42f5bfda35b98936257423f00e260498f Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 15 Jan 2016 14:17:29 +0100 Subject: [PATCH] Remove temporary allocations by extending the lifetime of the retval. See also Herb Sutter's article on the "most important const": http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/ When running the CMake daemon on the KDevelop build dir, this removes some hundreds of thousands of temporary allocations. This hotspot was found with heaptrack. --- Source/cmGlobalGenerator.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 2126c7180..b9296c119 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2198,9 +2198,9 @@ cmGlobalGenerator::FindGeneratorTargetImpl(std::string const& name) const { for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector tgts = + const std::vector& tgts = this->LocalGenerators[i]->GetGeneratorTargets(); - for (std::vector::iterator it = tgts.begin(); + for (std::vector::const_iterator it = tgts.begin(); it != tgts.end(); ++it) { if ((*it)->GetName() == name) @@ -2217,9 +2217,9 @@ cmGlobalGenerator::FindImportedTargetImpl(std::string const& name) const { for (unsigned int i = 0; i < this->Makefiles.size(); ++i) { - std::vector tgts = + const std::vector& tgts = this->Makefiles[i]->GetOwnedImportedTargets(); - for (std::vector::iterator it = tgts.begin(); + for (std::vector::const_iterator it = tgts.begin(); it != tgts.end(); ++it) { if ((*it)->GetName() == name && (*it)->IsImportedGloballyVisible()) @@ -2236,9 +2236,9 @@ cmGeneratorTarget* cmGlobalGenerator::FindImportedGeneratorTargetImpl( { for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector tgts = + const std::vector& tgts = this->LocalGenerators[i]->GetImportedGeneratorTargets(); - for (std::vector::iterator it = tgts.begin(); + for (std::vector::const_iterator it = tgts.begin(); it != tgts.end(); ++it) { if ((*it)->IsImportedGloballyVisible() && (*it)->GetName() == name)