[PATCH] D157048: [clang] NFC: Avoid double allocation when generating command line

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 3 15:40:56 PDT 2023


jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch makes use of the infrastructure established in D157046 <https://reviews.llvm.org/D157046> to avoid needless allocations via `StringSaver`.

Depends on D157046 <https://reviews.llvm.org/D157046>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157048

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@
 }
 
 std::vector<std::string> CompilerInvocation::getCC1CommandLine() const {
-  // Set up string allocator.
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Strings(Alloc);
-  auto SA = [&Strings](const Twine &Arg) { return Strings.save(Arg).data(); };
-
-  // Synthesize full command line from the CompilerInvocation, including "-cc1".
-  SmallVector<const char *, 32> Args{"-cc1"};
-  generateCC1CommandLine(Args, SA);
-
-  // Convert arguments to the return type.
-  return std::vector<std::string>{Args.begin(), Args.end()};
+  std::vector<std::string> Args{"-cc1"};
+  generateCC1CommandLine(
+      [&Args](const Twine &Arg) { Args.push_back(Arg.str()); });
+  return Args;
 }
 
 void CompilerInvocation::resetNonModularOptions() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157048.547029.patch
Type: text/x-patch
Size: 978 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230803/619cfc7f/attachment.bin>


More information about the cfe-commits mailing list