diff --git a/llvm/include/llvm/Testing/Support/Error.h b/llvm/include/llvm/Testing/Support/Error.h --- a/llvm/include/llvm/Testing/Support/Error.h +++ b/llvm/include/llvm/Testing/Support/Error.h @@ -139,7 +139,8 @@ bool MatchAndExplain(const ErrorHolder &Holder, testing::MatchResultListener *listener) const override { std::vector Messages; - for (const std::shared_ptr &Info: Holder.Infos) + Messages.reserve(Holder.Infos.size()); + for (const std::shared_ptr &Info : Holder.Infos) Messages.push_back(Info->message()); return Matcher.MatchAndExplain(Messages, listener); diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -1506,6 +1506,7 @@ std::vector RedirectingFileSystem::getRoots() const { std::vector R; + R.reserve(Roots.size()); for (const auto &Root : Roots) R.push_back(Root->getName()); return R; diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -554,6 +554,7 @@ // Invoke the demangler. std::vector ArgsV; + ArgsV.reserve(ViewOpts.DemanglerOpts.size()); for (StringRef Arg : ViewOpts.DemanglerOpts) ArgsV.push_back(Arg); std::optional Redirects[] = { diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp --- a/llvm/tools/llvm-cov/CoverageReport.cpp +++ b/llvm/tools/llvm-cov/CoverageReport.cpp @@ -437,6 +437,7 @@ prepareFileReports(Coverage, Totals, Files, Options, Filters); std::vector Filenames; + Filenames.reserve(FileReports.size()); for (const FileCoverageSummary &FCS : FileReports) Filenames.emplace_back(FCS.Name); adjustColumnWidths(Filenames, {}); diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp @@ -446,6 +446,7 @@ std::vector> Values; // The size is a random value greater than 64 (hardcoded DenseMap min init) const int Count = 65; + Values.reserve(Count); for (int i = 0; i < Count; i++) Values.emplace_back(i, CountCopyAndMove()); diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -5858,6 +5858,7 @@ // Emit a table containing the PredicateBitsets objects needed by the matcher // and an enum for the matcher to reference them with. std::vector> FeatureBitsets; + FeatureBitsets.reserve(Rules.size()); for (auto &Rule : Rules) FeatureBitsets.push_back(Rule.getRequiredFeatures()); llvm::sort(FeatureBitsets, [&](const std::vector &A, diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp --- a/llvm/utils/TableGen/OptParserEmitter.cpp +++ b/llvm/utils/TableGen/OptParserEmitter.cpp @@ -424,6 +424,7 @@ CmpMarshallingOpts); std::vector MarshallingInfos; + MarshallingInfos.reserve(OptsWithMarshalling.size()); for (const auto *R : OptsWithMarshalling) MarshallingInfos.push_back(createMarshallingInfo(*R));