Use StringRef in StringSaver API (NFC)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283290 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mehdi Amini 2016-10-05 01:32:41 +00:00
parent ba066c0ba6
commit 1455db37f5
3 changed files with 11 additions and 11 deletions

View File

@ -23,10 +23,10 @@ class StringSaver final {
public:
StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {}
const char *save(const char *S) { return save(StringRef(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)); }
StringRef save(const char *S) { return save(StringRef(S)); }
StringRef save(StringRef S);
StringRef save(const Twine &S) { return save(StringRef(S.str())); }
StringRef save(std::string &S) { return save(StringRef(S)); }
};
}
#endif

View File

@ -726,7 +726,7 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver,
// End the token if this is whitespace.
if (isWhitespace(Src[I])) {
if (!Token.empty())
NewArgv.push_back(Saver.save(StringRef(Token)));
NewArgv.push_back(Saver.save(StringRef(Token)).data());
Token.clear();
continue;
}
@ -737,7 +737,7 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver,
// Append the last token after hitting EOF with no whitespace.
if (!Token.empty())
NewArgv.push_back(Saver.save(StringRef(Token)));
NewArgv.push_back(Saver.save(StringRef(Token)).data());
// Mark the end of response files
if (MarkEOLs)
NewArgv.push_back(nullptr);
@ -818,7 +818,7 @@ void cl::TokenizeWindowsCommandLine(StringRef Src, StringSaver &Saver,
if (State == UNQUOTED) {
// Whitespace means the end of the token.
if (isWhitespace(Src[I])) {
NewArgv.push_back(Saver.save(StringRef(Token)));
NewArgv.push_back(Saver.save(StringRef(Token)).data());
Token.clear();
State = INIT;
// Mark the end of lines in response files
@ -853,7 +853,7 @@ void cl::TokenizeWindowsCommandLine(StringRef Src, StringSaver &Saver,
}
// Append the last token after hitting EOF with no whitespace.
if (!Token.empty())
NewArgv.push_back(Saver.save(StringRef(Token)));
NewArgv.push_back(Saver.save(StringRef(Token)).data());
// Mark the end of response files
if (MarkEOLs)
NewArgv.push_back(nullptr);
@ -962,7 +962,7 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar,
SmallVector<const char *, 20> newArgv;
BumpPtrAllocator A;
StringSaver Saver(A);
newArgv.push_back(Saver.save(progName));
newArgv.push_back(Saver.save(progName).data());
// Parse the value of the environment variable into a "command line"
// and hand it off to ParseCommandLineOptions().

View File

@ -11,9 +11,9 @@
using namespace llvm;
const char *StringSaver::save(StringRef S) {
StringRef StringSaver::save(StringRef S) {
char *P = Alloc.Allocate<char>(S.size() + 1);
memcpy(P, S.data(), S.size());
P[S.size()] = '\0';
return P;
return StringRef(P, S.size());
}