[PATCH] D139483: Reserve memory before pushing back

Alf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 16:34:24 PST 2022


gAlfonso-bit updated this revision to Diff 480686.
gAlfonso-bit added a comment.

Resolved changes


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139483/new/

https://reviews.llvm.org/D139483

Files:
  llvm/include/llvm/Testing/Support/Error.h
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/tools/llvm-cov/CodeCoverage.cpp
  llvm/tools/llvm-cov/CoverageReport.cpp
  llvm/unittests/ADT/DenseMapTest.cpp
  llvm/utils/TableGen/GlobalISelEmitter.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139483.480686.patch
Type: text/x-patch
Size: 3644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221207/2b138c83/attachment.bin>


More information about the llvm-commits mailing list