From 42fe3754c5078257d5d62e7dec91a0a62be5819d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 13 Aug 2015 01:07:02 +0000 Subject: [PATCH] There is only one saver of strings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244854 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/CommandLine.h | 1 - include/llvm/Support/StringSaver.h | 16 +++------------- lib/LibDriver/LibDriver.cpp | 2 +- lib/Support/CommandLine.cpp | 4 ++-- lib/Support/StringSaver.cpp | 2 +- unittests/Support/CommandLineTest.cpp | 2 +- 6 files changed, 8 insertions(+), 19 deletions(-) diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index 379d06a6574..467dc128aea 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -33,7 +33,6 @@ namespace llvm { -class BumpPtrStringSaver; class StringSaver; /// cl Namespace - This namespace contains all of the command line option diff --git a/include/llvm/Support/StringSaver.h b/include/llvm/Support/StringSaver.h index f3853ee9157..38fb7bb3833 100644 --- a/include/llvm/Support/StringSaver.h +++ b/include/llvm/Support/StringSaver.h @@ -18,25 +18,15 @@ namespace llvm { /// \brief Saves strings in the inheritor's stable storage and returns a stable /// raw character pointer. -class StringSaver { -protected: - ~StringSaver() {} - virtual const char *saveImpl(StringRef S); +class StringSaver final { + BumpPtrAllocator &Alloc; public: StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {} const char *save(const char *S) { return save(StringRef(S)); } - const char *save(StringRef S) { return saveImpl(S); } + const char *save(StringRef S); const char *save(const Twine &S) { return save(StringRef(S.str())); } const char *save(std::string &S) { return save(StringRef(S)); } - -private: - BumpPtrAllocator &Alloc; -}; - -class BumpPtrStringSaver final : public StringSaver { -public: - BumpPtrStringSaver(BumpPtrAllocator &Alloc) : StringSaver(Alloc) {} }; } #endif diff --git a/lib/LibDriver/LibDriver.cpp b/lib/LibDriver/LibDriver.cpp index ff9c31cd975..cc5c543888c 100644 --- a/lib/LibDriver/LibDriver.cpp +++ b/lib/LibDriver/LibDriver.cpp @@ -102,7 +102,7 @@ static Optional findInputFile(StringRef File, int llvm::libDriverMain(llvm::ArrayRef ArgsArr) { SmallVector NewArgs(ArgsArr.begin(), ArgsArr.end()); BumpPtrAllocator Alloc; - BumpPtrStringSaver Saver(Alloc); + StringSaver Saver(Alloc); cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs); ArgsArr = NewArgs; diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 17fba95ebb2..11162ce0ec4 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -799,7 +799,7 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar, // telling us. SmallVector newArgv; BumpPtrAllocator A; - BumpPtrStringSaver Saver(A); + StringSaver Saver(A); newArgv.push_back(Saver.save(progName)); // Parse the value of the environment variable into a "command line" @@ -822,7 +822,7 @@ void CommandLineParser::ParseCommandLineOptions(int argc, // Expand response files. SmallVector newArgv(argv, argv + argc); BumpPtrAllocator A; - BumpPtrStringSaver Saver(A); + StringSaver Saver(A); ExpandResponseFiles(Saver, TokenizeGNUCommandLine, newArgv); argv = &newArgv[0]; argc = static_cast(newArgv.size()); diff --git a/lib/Support/StringSaver.cpp b/lib/Support/StringSaver.cpp index d6b84e53dcc..bbc1fd27626 100644 --- a/lib/Support/StringSaver.cpp +++ b/lib/Support/StringSaver.cpp @@ -11,7 +11,7 @@ using namespace llvm; -const char *StringSaver::saveImpl(StringRef S) { +const char *StringSaver::save(StringRef S) { char *P = Alloc.Allocate(S.size() + 1); memcpy(P, S.data(), S.size()); P[S.size()] = '\0'; diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp index e0fbf5b09e5..2ae30c21ec4 100644 --- a/unittests/Support/CommandLineTest.cpp +++ b/unittests/Support/CommandLineTest.cpp @@ -155,7 +155,7 @@ void testCommandLineTokenizer(ParserFunction *parse, const char *Input, const char *const Output[], size_t OutputSize) { SmallVector Actual; BumpPtrAllocator A; - BumpPtrStringSaver Saver(A); + StringSaver Saver(A); parse(Input, Saver, Actual, /*MarkEOLs=*/false); EXPECT_EQ(OutputSize, Actual.size()); for (unsigned I = 0, E = Actual.size(); I != E; ++I) { -- 2.34.1