Author: Jan Svoboda
Date: 2023-08-03T20:35:42-07:00
New Revision: acd1ab869fca0cfa09065aac518da399f755ed5c

URL: 
https://github.com/llvm/llvm-project/commit/acd1ab869fca0cfa09065aac518da399f755ed5c
DIFF: 
https://github.com/llvm/llvm-project/commit/acd1ab869fca0cfa09065aac518da399f755ed5c.diff

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

This patch makes use of the infrastructure established in D157046 to avoid 
needless allocations via `StringSaver`.

Depends on D157046.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D157048

Added: 
    

Modified: 
    clang/lib/Frontend/CompilerInvocation.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2e2f1de36482fa..be53ce3e472659 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@ void CompilerInvocation::generateCC1CommandLine(
 }
 
 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() {


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to