r260815 - Reduce the number of implicit StringRef->std::string conversions by threading StringRef through more APIs.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 13 05:42:54 PST 2016
Author: d0k
Date: Sat Feb 13 07:42:54 2016
New Revision: 260815
URL: http://llvm.org/viewvc/llvm-project?rev=260815&view=rev
Log:
Reduce the number of implicit StringRef->std::string conversions by threading StringRef through more APIs.
No functionality change intended.
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Index/CommentToXML.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
cfe/trunk/tools/driver/driver.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Sat Feb 13 07:42:54 2016
@@ -1844,8 +1844,9 @@ inline internal::Matcher<Stmt> sizeOfExp
/// \code
/// namespace a { namespace b { class X; } }
/// \endcode
-inline internal::Matcher<NamedDecl> hasName(const std::string &Name) {
- return internal::Matcher<NamedDecl>(new internal::HasNameMatcher(Name));
+inline internal::Matcher<NamedDecl> hasName(std::string Name) {
+ return internal::Matcher<NamedDecl>(
+ new internal::HasNameMatcher(std::move(Name)));
}
/// \brief Matches NamedDecl nodes whose fully qualified names contain
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Sat Feb 13 07:42:54 2016
@@ -640,7 +640,7 @@ private:
/// See \c hasName() in ASTMatchers.h for details.
class HasNameMatcher : public SingleNodeMatcherInterface<NamedDecl> {
public:
- explicit HasNameMatcher(StringRef Name);
+ explicit HasNameMatcher(std::string Name);
bool matchesNode(const NamedDecl &Node) const override;
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Sat Feb 13 07:42:54 2016
@@ -1364,7 +1364,7 @@ public:
/// \param ClientLoadCapabilities The set of client load-failure
/// capabilities, represented as a bitset of the enumerators of
/// LoadFailureCapabilities.
- ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type,
+ ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
SourceLocation ImportLoc,
unsigned ClientLoadCapabilities);
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h Sat Feb 13 07:42:54 2016
@@ -774,8 +774,8 @@ public:
void appendToDesc(StringRef S) {
if (!ShortDesc.empty())
- ShortDesc.append(S);
- VerboseDesc.append(S);
+ ShortDesc += S;
+ VerboseDesc += S;
}
void resetPath() {
Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Sat Feb 13 07:42:54 2016
@@ -293,8 +293,9 @@ bool AnyOfVariadicOperator(const ast_typ
return false;
}
-HasNameMatcher::HasNameMatcher(StringRef NameRef)
- : UseUnqualifiedMatch(NameRef.find("::") == NameRef.npos), Name(NameRef) {
+HasNameMatcher::HasNameMatcher(std::string NameRef)
+ : UseUnqualifiedMatch(NameRef.find("::") == NameRef.npos),
+ Name(std::move(NameRef)) {
assert(!Name.empty());
}
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sat Feb 13 07:42:54 2016
@@ -591,7 +591,7 @@ public:
return NULLPtr;
}
- llvm::GlobalVariable *GetClassGlobal(const std::string &Name,
+ llvm::GlobalVariable *GetClassGlobal(StringRef Name,
bool Weak = false) override {
return nullptr;
}
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sat Feb 13 07:42:54 2016
@@ -1256,7 +1256,7 @@ public:
/// GetClassGlobal - Return the global variable for the Objective-C
/// class of the given name.
- llvm::GlobalVariable *GetClassGlobal(const std::string &Name,
+ llvm::GlobalVariable *GetClassGlobal(StringRef Name,
bool Weak = false) override {
llvm_unreachable("CGObjCMac::GetClassGlobal");
}
@@ -1358,7 +1358,7 @@ private:
/// GetClassGlobal - Return the global variable for the Objective-C
/// class of the given name.
- llvm::GlobalVariable *GetClassGlobal(const std::string &Name,
+ llvm::GlobalVariable *GetClassGlobal(StringRef Name,
bool Weak = false) override;
/// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
@@ -6834,7 +6834,7 @@ CGObjCNonFragileABIMac::GenerateMessageS
}
llvm::GlobalVariable *
-CGObjCNonFragileABIMac::GetClassGlobal(const std::string &Name, bool Weak) {
+CGObjCNonFragileABIMac::GetClassGlobal(StringRef Name, bool Weak) {
llvm::GlobalValue::LinkageTypes L =
Weak ? llvm::GlobalValue::ExternalWeakLinkage
: llvm::GlobalValue::ExternalLinkage;
Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Sat Feb 13 07:42:54 2016
@@ -280,7 +280,7 @@ public:
virtual llvm::Constant *BuildByrefLayout(CodeGen::CodeGenModule &CGM,
QualType T) = 0;
- virtual llvm::GlobalVariable *GetClassGlobal(const std::string &Name,
+ virtual llvm::GlobalVariable *GetClassGlobal(StringRef Name,
bool Weak = false) = 0;
struct MessageSendInfo {
Modified: cfe/trunk/lib/Frontend/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CacheTokens.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CacheTokens.cpp (original)
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp Sat Feb 13 07:42:54 2016
@@ -241,7 +241,7 @@ public:
: Out(out), PP(pp), idcount(0), CurStrOffset(0) {}
PTHMap &getPM() { return PM; }
- void GeneratePTH(const std::string &MainFile);
+ void GeneratePTH(StringRef MainFile);
};
} // end anonymous namespace
@@ -479,7 +479,7 @@ static void pwrite32le(raw_pwrite_stream
Off += 4;
}
-void PTHWriter::GeneratePTH(const std::string &MainFile) {
+void PTHWriter::GeneratePTH(StringRef MainFile) {
// Generate the prologue.
Out << "cfe-pth" << '\0';
Emit32(PTHManager::Version);
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Sat Feb 13 07:42:54 2016
@@ -467,7 +467,7 @@ IntrusiveRefCntPtr<ASTReader> CompilerIn
// Code Completion
static bool EnableCodeCompletion(Preprocessor &PP,
- const std::string &Filename,
+ StringRef Filename,
unsigned Line,
unsigned Column) {
// Tell the source manager to chop off the given file at a specific
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Sat Feb 13 07:42:54 2016
@@ -369,18 +369,16 @@ void PrintPPOutputPPCallbacks::MacroUnde
setEmittedDirectiveOnThisLine();
}
-static void outputPrintable(llvm::raw_ostream& OS,
- const std::string &Str) {
- for (unsigned i = 0, e = Str.size(); i != e; ++i) {
- unsigned char Char = Str[i];
- if (isPrintable(Char) && Char != '\\' && Char != '"')
- OS << (char)Char;
- else // Output anything hard as an octal escape.
- OS << '\\'
- << (char)('0'+ ((Char >> 6) & 7))
- << (char)('0'+ ((Char >> 3) & 7))
- << (char)('0'+ ((Char >> 0) & 7));
- }
+static void outputPrintable(raw_ostream &OS, StringRef Str) {
+ for (unsigned char Char : Str) {
+ if (isPrintable(Char) && Char != '\\' && Char != '"')
+ OS << (char)Char;
+ else // Output anything hard as an octal escape.
+ OS << '\\'
+ << (char)('0' + ((Char >> 6) & 7))
+ << (char)('0' + ((Char >> 3) & 7))
+ << (char)('0' + ((Char >> 0) & 7));
+ }
}
void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc,
Modified: cfe/trunk/lib/Index/CommentToXML.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/CommentToXML.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/Index/CommentToXML.cpp (original)
+++ cfe/trunk/lib/Index/CommentToXML.cpp Sat Feb 13 07:42:54 2016
@@ -592,9 +592,8 @@ void getSourceTextOfDeclaration(const De
void CommentASTToXMLConverter::formatTextOfDeclaration(
const DeclInfo *DI, SmallString<128> &Declaration) {
- // FIXME. formatting API expects null terminated input string.
- // There might be more efficient way of doing this.
- std::string StringDecl = Declaration.str();
+ // Formatting API expects null terminated input string.
+ StringRef StringDecl(Declaration.c_str(), Declaration.size());
// Formatter specific code.
// Form a unique in memory buffer name.
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sat Feb 13 07:42:54 2016
@@ -3483,7 +3483,7 @@ static bool SkipCursorToBlock(BitstreamC
}
}
-ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
+ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
ModuleKind Type,
SourceLocation ImportLoc,
unsigned ClientLoadCapabilities) {
Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Sat Feb 13 07:42:54 2016
@@ -412,13 +412,13 @@ void HTMLDiagnostics::HandlePiece(Rewrit
// Output a maximum size.
if (!isa<PathDiagnosticMacroPiece>(P)) {
// Get the string and determining its maximum substring.
- const std::string& Msg = P.getString();
+ const auto &Msg = P.getString();
unsigned max_token = 0;
unsigned cnt = 0;
unsigned len = Msg.size();
- for (std::string::const_iterator I=Msg.begin(), E=Msg.end(); I!=E; ++I)
- switch (*I) {
+ for (char C : Msg)
+ switch (C) {
default:
++cnt;
continue;
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp Sat Feb 13 07:42:54 2016
@@ -124,7 +124,7 @@ static void ReportControlFlow(raw_ostrea
--indent;
// Output any helper text.
- const std::string& s = P.getString();
+ const auto &s = P.getString();
if (!s.empty()) {
Indent(o, indent) << "<key>alternate</key>";
EmitString(o, s) << '\n';
Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=260815&r1=260814&r2=260815&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Sat Feb 13 07:42:54 2016
@@ -130,7 +130,7 @@ static void ApplyOneQAOverride(raw_ostre
}
}
} 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();) {
if (Option == Args[i]) {
OS << "### Deleting argument " << Args[i] << '\n';
More information about the cfe-commits
mailing list