aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2023-08-03 15:40:18 -0700
committerJan Svoboda <jan_svoboda@apple.com>2023-08-03 20:35:42 -0700
commitacd1ab869fca0cfa09065aac518da399f755ed5c (patch)
treee56f6430a911393060411e557a8bd539098a87ac /clang/lib/Frontend/CompilerInvocation.cpp
parent83452650490eb1021939129682b01fcdff34c691 (diff)
downloadllvm-acd1ab869fca0cfa09065aac518da399f755ed5c.zip
llvm-acd1ab869fca0cfa09065aac518da399f755ed5c.tar.gz
llvm-acd1ab869fca0cfa09065aac518da399f755ed5c.tar.bz2
[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
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp15
1 files changed, 4 insertions, 11 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 2e2f1de..be53ce3 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() {