Hi.
Here are two patches for clang-tools-extra and for clang which simplifies code
a little bit and also removes possibility of implicit std::string construction.
--
Eugene
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h (revision 240271)
+++ include/clang/ASTMatchers/ASTMatchers.h (working copy)
@@ -112,7 +112,7 @@
///
/// FIXME: Do we want to support this now that we have bind()?
template <typename T>
-internal::Matcher<T> id(const std::string &ID,
+internal::Matcher<T> id(StringRef ID,
const internal::BindableMatcher<T> &InnerMatcher) {
return InnerMatcher.bind(ID);
}
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchersInternal.h (revision 240271)
+++ include/clang/ASTMatchers/ASTMatchersInternal.h (working copy)
@@ -140,8 +140,7 @@
};
/// \brief Add a binding from an id to a node.
- void setBinding(const std::string &Id,
- const ast_type_traits::DynTypedNode &DynNode) {
+ void setBinding(StringRef Id, const ast_type_traits::DynTypedNode &DynNode) {
if (Bindings.empty())
Bindings.emplace_back();
for (BoundNodesMap &Binding : Bindings)
Index: include/clang/ASTMatchers/Dynamic/VariantValue.h
===================================================================
--- include/clang/ASTMatchers/Dynamic/VariantValue.h (revision 240271)
+++ include/clang/ASTMatchers/Dynamic/VariantValue.h (working copy)
@@ -242,7 +242,7 @@
///
/// Supported types:
/// - \c unsigned
-/// - \c std::string
+/// - \c llvm::StringRef
/// - \c VariantMatcher (\c DynTypedMatcher / \c Matcher<T>)
class VariantValue {
public:
@@ -254,7 +254,7 @@
/// \brief Specific constructors for each supported type.
VariantValue(unsigned Unsigned);
- VariantValue(const std::string &String);
+ VariantValue(StringRef String);
VariantValue(const VariantMatcher &Matchers);
/// \brief Returns true iff this is not an empty value.
@@ -269,7 +269,7 @@
/// \brief String value functions.
bool isString() const;
const std::string &getString() const;
- void setString(const std::string &String);
+ void setString(StringRef String);
/// \brief Matcher value functions.
bool isMatcher() const;
Index: include/clang/Frontend/CompilerInstance.h
===================================================================
--- include/clang/Frontend/CompilerInstance.h (revision 240271)
+++ include/clang/Frontend/CompilerInstance.h (working copy)
@@ -157,9 +157,10 @@
std::string TempFilename;
std::unique_ptr<raw_ostream> OS;
- OutputFile(const std::string &filename, const std::string &tempFilename,
+ OutputFile(std::string filename, std::string tempFilename,
std::unique_ptr<raw_ostream> OS)
- : Filename(filename), TempFilename(tempFilename), OS(std::move(OS)) {}
+ : Filename(std::move(filename)), TempFilename(std::move(tempFilename)),
+ OS(std::move(OS)) {}
OutputFile(OutputFile &&O)
: Filename(std::move(O.Filename)),
TempFilename(std::move(O.TempFilename)), OS(std::move(O.OS)) {}
@@ -614,7 +615,7 @@
///
/// \return - The new object on success, or null on failure.
static IntrusiveRefCntPtr<ASTReader> createPCHExternalASTSource(
- StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,
+ StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
const PCHContainerOperations &PCHContainerOps,
void *DeserializationListener, bool OwnDeserializationListener,
@@ -627,11 +628,9 @@
/// Create a code completion consumer to print code completion results, at
/// \p Filename, \p Line, and \p Column, to the given output stream \p OS.
- static CodeCompleteConsumer *
- createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename,
- unsigned Line, unsigned Column,
- const CodeCompleteOptions &Opts,
- raw_ostream &OS);
+ static CodeCompleteConsumer *createCodeCompletionConsumer(
+ Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column,
+ const CodeCompleteOptions &Opts, raw_ostream &OS);
/// \brief Create the Sema object to be used for parsing.
void createSema(TranslationUnitKind TUKind,
Index: lib/ASTMatchers/Dynamic/Parser.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Parser.cpp (revision 240271)
+++ lib/ASTMatchers/Dynamic/Parser.cpp (working copy)
@@ -216,7 +216,7 @@
if (Code[Length] == Marker) {
Result->Kind = TokenInfo::TK_Literal;
Result->Text = Code.substr(0, Length + 1);
- Result->Value = Code.substr(1, Length - 1).str();
+ Result->Value = Code.substr(1, Length - 1);
Code = Code.drop_front(Length + 1);
return;
}
Index: lib/ASTMatchers/Dynamic/VariantValue.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/VariantValue.cpp (revision 240271)
+++ lib/ASTMatchers/Dynamic/VariantValue.cpp (working copy)
@@ -249,7 +249,7 @@
setUnsigned(Unsigned);
}
-VariantValue::VariantValue(const std::string &String) : Type(VT_Nothing) {
+VariantValue::VariantValue(StringRef String) : Type(VT_Nothing) {
setString(String);
}
@@ -319,7 +319,7 @@
return *Value.String;
}
-void VariantValue::setString(const std::string &NewValue) {
+void VariantValue::setString(StringRef NewValue) {
reset();
Type = VT_String;
Value.String = new std::string(NewValue);
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp (revision 240271)
+++ lib/Frontend/CompilerInstance.cpp (working copy)
@@ -405,7 +405,7 @@
}
IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(
- StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,
+ StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
const PCHContainerOperations &PCHContainerOps,
void *DeserializationListener, bool OwnDeserializationListener,
@@ -413,7 +413,7 @@
HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
IntrusiveRefCntPtr<ASTReader> Reader(new ASTReader(
- PP, Context, PCHContainerOps, Sysroot.empty() ? "" : Sysroot.c_str(),
+ PP, Context, PCHContainerOps, Sysroot.empty() ? "" : Sysroot.data(),
DisablePCHValidation, AllowPCHWithCompilerErrors,
/*AllowConfigurationMismatch*/ false, HSOpts.ModulesValidateSystemHeaders,
UseGlobalModuleIndex));
@@ -502,7 +502,7 @@
CodeCompleteConsumer *
CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
- const std::string &Filename,
+ StringRef Filename,
unsigned Line,
unsigned Column,
const CodeCompleteOptions &Opts,
Index: clang-modernize/LoopConvert/StmtAncestor.h
===================================================================
--- clang-modernize/LoopConvert/StmtAncestor.h (revision 240271)
+++ clang-modernize/LoopConvert/StmtAncestor.h (working copy)
@@ -170,9 +170,9 @@
class DeclFinderASTVisitor :
public clang::RecursiveASTVisitor<DeclFinderASTVisitor> {
public:
- DeclFinderASTVisitor(const std::string &Name,
- const StmtGeneratedVarNameMap *GeneratedDecls) :
- Name(Name), GeneratedDecls(GeneratedDecls), Found(false) { }
+ DeclFinderASTVisitor(std::string Name,
+ const StmtGeneratedVarNameMap *GeneratedDecls)
+ : Name(std::move(Name)), GeneratedDecls(GeneratedDecls), Found(false) {}
/// Attempts to find any usages of variables name Name in Body, returning
/// true when it is used in Body. This includes the generated loop variables
Index: clang-rename/RenamingAction.cpp
===================================================================
--- clang-rename/RenamingAction.cpp (revision 240271)
+++ clang-rename/RenamingAction.cpp (working copy)
@@ -37,14 +37,11 @@
class RenamingASTConsumer : public ASTConsumer {
public:
- RenamingASTConsumer(const std::string &NewName,
- const std::string &PrevName,
+ RenamingASTConsumer(StringRef NewName, StringRef PrevName,
const std::vector<std::string> &USRs,
- tooling::Replacements &Replaces,
- bool PrintLocations)
+ tooling::Replacements &Replaces, bool PrintLocations)
: NewName(NewName), PrevName(PrevName), USRs(USRs), Replaces(Replaces),
- PrintLocations(PrintLocations) {
- }
+ PrintLocations(PrintLocations) {}
void HandleTranslationUnit(ASTContext &Context) override {
const auto &SourceMgr = Context.getSourceManager();
@@ -58,7 +55,7 @@
NewCandidates.clear();
}
- auto PrevNameLen = PrevName.length();
+ auto PrevNameLen = PrevName.size();
if (PrintLocations)
for (const auto &Loc : RenamingCandidates) {
FullSourceLoc FullLoc(Loc, SourceMgr);
@@ -75,7 +72,7 @@
}
private:
- const std::string &NewName, &PrevName;
+ StringRef NewName, PrevName;
const std::vector<std::string> &USRs;
tooling::Replacements &Replaces;
bool PrintLocations;
Index: clang-rename/RenamingAction.h
===================================================================
--- clang-rename/RenamingAction.h (revision 240271)
+++ clang-rename/RenamingAction.h (working copy)
@@ -25,7 +25,7 @@
class RenamingAction {
public:
- RenamingAction(const std::string &NewName, const std::string &PrevName,
+ RenamingAction(llvm::StringRef NewName, llvm::StringRef PrevName,
const std::vector<std::string> &USRs,
tooling::Replacements &Replaces, bool PrintLocations = false)
: NewName(NewName), PrevName(PrevName), USRs(USRs), Replaces(Replaces),
@@ -35,7 +35,7 @@
std::unique_ptr<ASTConsumer> newASTConsumer();
private:
- const std::string &NewName, &PrevName;
+ llvm::StringRef NewName, PrevName;
const std::vector<std::string> &USRs;
tooling::Replacements &Replaces;
bool PrintLocations;
Index: modularize/Modularize.cpp
===================================================================
--- modularize/Modularize.cpp (revision 240271)
+++ modularize/Modularize.cpp (working copy)
@@ -466,9 +466,9 @@
public:
DenseMap<const FileEntry *, HeaderContents> HeaderContentMismatches;
- void add(const std::string &Name, enum Entry::EntryKind Kind, Location Loc) {
+ void add(std::string Name, enum Entry::EntryKind Kind, Location Loc) {
// Record this entity in its header.
- HeaderEntry HE = { Name, Loc };
+ HeaderEntry HE = {std::move(Name), Loc};
CurHeaderContents[Loc.File].push_back(HE);
// Check whether we've seen this entry before.
Index: pp-trace/PPCallbacksTracker.cpp
===================================================================
--- pp-trace/PPCallbacksTracker.cpp (revision 240271)
+++ pp-trace/PPCallbacksTracker.cpp (working copy)
@@ -627,7 +627,7 @@
// Append a double-quoted argument to the top trace item.
void PPCallbacksTracker::appendQuotedArgument(const char *Name,
- const std::string &Value) {
+ llvm::StringRef Value) {
std::string Str;
llvm::raw_string_ostream SS(Str);
SS << "\"" << Value << "\"";
Index: pp-trace/PPCallbacksTracker.h
===================================================================
--- pp-trace/PPCallbacksTracker.h (revision 240271)
+++ pp-trace/PPCallbacksTracker.h (working copy)
@@ -215,7 +215,7 @@
void appendArgument(const char *Name, const clang::Module *Value);
/// \brief Append a double-quoted argument to the top trace item.
- void appendQuotedArgument(const char *Name, const std::string &Value);
+ void appendQuotedArgument(const char *Name, llvm::StringRef Value);
/// \brief Append a double-quoted file path argument to the top trace item.
void appendFilePathArgument(const char *Name, llvm::StringRef Value);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits