From acd1ab869fca0cfa09065aac518da399f755ed5c Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 3 Aug 2023 15:40:18 -0700 Subject: [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 --- clang/lib/Frontend/CompilerInvocation.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') 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 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 Args{"-cc1"}; - generateCC1CommandLine(Args, SA); - - // Convert arguments to the return type. - return std::vector{Args.begin(), Args.end()}; + std::vector Args{"-cc1"}; + generateCC1CommandLine( + [&Args](const Twine &Arg) { Args.push_back(Arg.str()); }); + return Args; } void CompilerInvocation::resetNonModularOptions() { -- cgit v1.1