Skip to content

Commit acd1ab8

Browse files
committed
[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
1 parent 8345265 commit acd1ab8

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4611,17 +4611,10 @@ void CompilerInvocation::generateCC1CommandLine(
46114611
}
46124612

46134613
std::vector<std::string> CompilerInvocation::getCC1CommandLine() const {
4614-
// Set up string allocator.
4615-
llvm::BumpPtrAllocator Alloc;
4616-
llvm::StringSaver Strings(Alloc);
4617-
auto SA = [&Strings](const Twine &Arg) { return Strings.save(Arg).data(); };
4618-
4619-
// Synthesize full command line from the CompilerInvocation, including "-cc1".
4620-
SmallVector<const char *, 32> Args{"-cc1"};
4621-
generateCC1CommandLine(Args, SA);
4622-
4623-
// Convert arguments to the return type.
4624-
return std::vector<std::string>{Args.begin(), Args.end()};
4614+
std::vector<std::string> Args{"-cc1"};
4615+
generateCC1CommandLine(
4616+
[&Args](const Twine &Arg) { Args.push_back(Arg.str()); });
4617+
return Args;
46254618
}
46264619

46274620
void CompilerInvocation::resetNonModularOptions() {

0 commit comments

Comments
 (0)