Reduce the number of implicit StringRef->std::string conversions by threading StringRef through more APIs.

No functionality change intended.

llvm-svn: 260815
This commit is contained in:
Benjamin Kramer 2016-02-13 13:42:54 +00:00
parent 2193e23cd7
commit 0772c42385
16 changed files with 36 additions and 37 deletions

View File

@ -1844,8 +1844,9 @@ inline internal::Matcher<Stmt> sizeOfExpr(
/// \code /// \code
/// namespace a { namespace b { class X; } } /// namespace a { namespace b { class X; } }
/// \endcode /// \endcode
inline internal::Matcher<NamedDecl> hasName(const std::string &Name) { inline internal::Matcher<NamedDecl> hasName(std::string Name) {
return internal::Matcher<NamedDecl>(new internal::HasNameMatcher(Name)); return internal::Matcher<NamedDecl>(
new internal::HasNameMatcher(std::move(Name)));
} }
/// \brief Matches NamedDecl nodes whose fully qualified names contain /// \brief Matches NamedDecl nodes whose fully qualified names contain

View File

@ -640,7 +640,7 @@ private:
/// See \c hasName() in ASTMatchers.h for details. /// See \c hasName() in ASTMatchers.h for details.
class HasNameMatcher : public SingleNodeMatcherInterface<NamedDecl> { class HasNameMatcher : public SingleNodeMatcherInterface<NamedDecl> {
public: public:
explicit HasNameMatcher(StringRef Name); explicit HasNameMatcher(std::string Name);
bool matchesNode(const NamedDecl &Node) const override; bool matchesNode(const NamedDecl &Node) const override;

View File

@ -1364,7 +1364,7 @@ public:
/// \param ClientLoadCapabilities The set of client load-failure /// \param ClientLoadCapabilities The set of client load-failure
/// capabilities, represented as a bitset of the enumerators of /// capabilities, represented as a bitset of the enumerators of
/// LoadFailureCapabilities. /// LoadFailureCapabilities.
ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type, ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
SourceLocation ImportLoc, SourceLocation ImportLoc,
unsigned ClientLoadCapabilities); unsigned ClientLoadCapabilities);

View File

@ -774,8 +774,8 @@ public:
void appendToDesc(StringRef S) { void appendToDesc(StringRef S) {
if (!ShortDesc.empty()) if (!ShortDesc.empty())
ShortDesc.append(S); ShortDesc += S;
VerboseDesc.append(S); VerboseDesc += S;
} }
void resetPath() { void resetPath() {

View File

@ -293,8 +293,9 @@ bool AnyOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode,
return false; return false;
} }
HasNameMatcher::HasNameMatcher(StringRef NameRef) HasNameMatcher::HasNameMatcher(std::string NameRef)
: UseUnqualifiedMatch(NameRef.find("::") == NameRef.npos), Name(NameRef) { : UseUnqualifiedMatch(NameRef.find("::") == NameRef.npos),
Name(std::move(NameRef)) {
assert(!Name.empty()); assert(!Name.empty());
} }

View File

@ -591,7 +591,7 @@ public:
return NULLPtr; return NULLPtr;
} }
llvm::GlobalVariable *GetClassGlobal(const std::string &Name, llvm::GlobalVariable *GetClassGlobal(StringRef Name,
bool Weak = false) override { bool Weak = false) override {
return nullptr; return nullptr;
} }

View File

@ -1256,7 +1256,7 @@ public:
/// GetClassGlobal - Return the global variable for the Objective-C /// GetClassGlobal - Return the global variable for the Objective-C
/// class of the given name. /// class of the given name.
llvm::GlobalVariable *GetClassGlobal(const std::string &Name, llvm::GlobalVariable *GetClassGlobal(StringRef Name,
bool Weak = false) override { bool Weak = false) override {
llvm_unreachable("CGObjCMac::GetClassGlobal"); llvm_unreachable("CGObjCMac::GetClassGlobal");
} }
@ -1358,7 +1358,7 @@ private:
/// GetClassGlobal - Return the global variable for the Objective-C /// GetClassGlobal - Return the global variable for the Objective-C
/// class of the given name. /// class of the given name.
llvm::GlobalVariable *GetClassGlobal(const std::string &Name, llvm::GlobalVariable *GetClassGlobal(StringRef Name,
bool Weak = false) override; bool Weak = false) override;
/// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy, /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
@ -6834,7 +6834,7 @@ CGObjCNonFragileABIMac::GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
} }
llvm::GlobalVariable * llvm::GlobalVariable *
CGObjCNonFragileABIMac::GetClassGlobal(const std::string &Name, bool Weak) { CGObjCNonFragileABIMac::GetClassGlobal(StringRef Name, bool Weak) {
llvm::GlobalValue::LinkageTypes L = llvm::GlobalValue::LinkageTypes L =
Weak ? llvm::GlobalValue::ExternalWeakLinkage Weak ? llvm::GlobalValue::ExternalWeakLinkage
: llvm::GlobalValue::ExternalLinkage; : llvm::GlobalValue::ExternalLinkage;

View File

@ -280,7 +280,7 @@ public:
virtual llvm::Constant *BuildByrefLayout(CodeGen::CodeGenModule &CGM, virtual llvm::Constant *BuildByrefLayout(CodeGen::CodeGenModule &CGM,
QualType T) = 0; QualType T) = 0;
virtual llvm::GlobalVariable *GetClassGlobal(const std::string &Name, virtual llvm::GlobalVariable *GetClassGlobal(StringRef Name,
bool Weak = false) = 0; bool Weak = false) = 0;
struct MessageSendInfo { struct MessageSendInfo {

View File

@ -241,7 +241,7 @@ public:
: Out(out), PP(pp), idcount(0), CurStrOffset(0) {} : Out(out), PP(pp), idcount(0), CurStrOffset(0) {}
PTHMap &getPM() { return PM; } PTHMap &getPM() { return PM; }
void GeneratePTH(const std::string &MainFile); void GeneratePTH(StringRef MainFile);
}; };
} // end anonymous namespace } // end anonymous namespace
@ -479,7 +479,7 @@ static void pwrite32le(raw_pwrite_stream &OS, uint32_t Val, uint64_t &Off) {
Off += 4; Off += 4;
} }
void PTHWriter::GeneratePTH(const std::string &MainFile) { void PTHWriter::GeneratePTH(StringRef MainFile) {
// Generate the prologue. // Generate the prologue.
Out << "cfe-pth" << '\0'; Out << "cfe-pth" << '\0';
Emit32(PTHManager::Version); Emit32(PTHManager::Version);

View File

@ -467,7 +467,7 @@ IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(
// Code Completion // Code Completion
static bool EnableCodeCompletion(Preprocessor &PP, static bool EnableCodeCompletion(Preprocessor &PP,
const std::string &Filename, StringRef Filename,
unsigned Line, unsigned Line,
unsigned Column) { unsigned Column) {
// Tell the source manager to chop off the given file at a specific // Tell the source manager to chop off the given file at a specific

View File

@ -369,18 +369,16 @@ void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
setEmittedDirectiveOnThisLine(); setEmittedDirectiveOnThisLine();
} }
static void outputPrintable(llvm::raw_ostream& OS, static void outputPrintable(raw_ostream &OS, StringRef Str) {
const std::string &Str) { for (unsigned char Char : Str) {
for (unsigned i = 0, e = Str.size(); i != e; ++i) { if (isPrintable(Char) && Char != '\\' && Char != '"')
unsigned char Char = Str[i]; OS << (char)Char;
if (isPrintable(Char) && Char != '\\' && Char != '"') else // Output anything hard as an octal escape.
OS << (char)Char; OS << '\\'
else // Output anything hard as an octal escape. << (char)('0' + ((Char >> 6) & 7))
OS << '\\' << (char)('0' + ((Char >> 3) & 7))
<< (char)('0'+ ((Char >> 6) & 7)) << (char)('0' + ((Char >> 0) & 7));
<< (char)('0'+ ((Char >> 3) & 7)) }
<< (char)('0'+ ((Char >> 0) & 7));
}
} }
void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc, void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc,

View File

@ -592,9 +592,8 @@ void getSourceTextOfDeclaration(const DeclInfo *ThisDecl,
void CommentASTToXMLConverter::formatTextOfDeclaration( void CommentASTToXMLConverter::formatTextOfDeclaration(
const DeclInfo *DI, SmallString<128> &Declaration) { const DeclInfo *DI, SmallString<128> &Declaration) {
// FIXME. formatting API expects null terminated input string. // Formatting API expects null terminated input string.
// There might be more efficient way of doing this. StringRef StringDecl(Declaration.c_str(), Declaration.size());
std::string StringDecl = Declaration.str();
// Formatter specific code. // Formatter specific code.
// Form a unique in memory buffer name. // Form a unique in memory buffer name.

View File

@ -3483,7 +3483,7 @@ static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) {
} }
} }
ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
ModuleKind Type, ModuleKind Type,
SourceLocation ImportLoc, SourceLocation ImportLoc,
unsigned ClientLoadCapabilities) { unsigned ClientLoadCapabilities) {

View File

@ -412,13 +412,13 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID,
// Output a maximum size. // Output a maximum size.
if (!isa<PathDiagnosticMacroPiece>(P)) { if (!isa<PathDiagnosticMacroPiece>(P)) {
// Get the string and determining its maximum substring. // Get the string and determining its maximum substring.
const std::string& Msg = P.getString(); const auto &Msg = P.getString();
unsigned max_token = 0; unsigned max_token = 0;
unsigned cnt = 0; unsigned cnt = 0;
unsigned len = Msg.size(); unsigned len = Msg.size();
for (std::string::const_iterator I=Msg.begin(), E=Msg.end(); I!=E; ++I) for (char C : Msg)
switch (*I) { switch (C) {
default: default:
++cnt; ++cnt;
continue; continue;

View File

@ -124,7 +124,7 @@ static void ReportControlFlow(raw_ostream &o,
--indent; --indent;
// Output any helper text. // Output any helper text.
const std::string& s = P.getString(); const auto &s = P.getString();
if (!s.empty()) { if (!s.empty()) {
Indent(o, indent) << "<key>alternate</key>"; Indent(o, indent) << "<key>alternate</key>";
EmitString(o, s) << '\n'; EmitString(o, s) << '\n';

View File

@ -130,7 +130,7 @@ static void ApplyOneQAOverride(raw_ostream &OS,
} }
} }
} else if (Edit[0] == 'x' || Edit[0] == 'X') { } else if (Edit[0] == 'x' || Edit[0] == 'X') {
std::string Option = Edit.substr(1, std::string::npos); auto Option = Edit.substr(1);
for (unsigned i = 1; i < Args.size();) { for (unsigned i = 1; i < Args.size();) {
if (Option == Args[i]) { if (Option == Args[i]) {
OS << "### Deleting argument " << Args[i] << '\n'; OS << "### Deleting argument " << Args[i] << '\n';