diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-02-13 08:30:43 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-02-13 11:24:43 +0100 |
commit | 38dcd3bc735633f2a4857849ef14917bbffcdd11 (patch) | |
tree | 98dcde5a1cacde29b33d563a3aece3fc746e4c5b | |
parent | 03d2fa836ebd5f8c05d1bda99c01be45a57b65ea (diff) |
Get rid of some unnecessary llvm::StringRef -> std::string conversions
(as discussed in the commit message of ce1d8e20a708ed031f2336770a41fbe501fe8225
"Adapt to '[ADT] Make StringRef's std::string conversion operator explicit'";
there are more of those that cannot easily be dropped, though).
Change-Id: Ib2e223f7de96ad8859eab165daa759b480326c7b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88582
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/constantparam.cxx | 4 | ||||
-rw-r--r-- | compilerplugins/clang/finalclasses.cxx | 12 | ||||
-rw-r--r-- | compilerplugins/clang/mergeclasses.cxx | 12 | ||||
-rw-r--r-- | compilerplugins/clang/useuniqueptr.cxx | 13 |
4 files changed, 17 insertions, 24 deletions
diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx index dd9bddd086c5..71c0f69da61a 100644 --- a/compilerplugins/clang/constantparam.cxx +++ b/compilerplugins/clang/constantparam.cxx @@ -275,7 +275,7 @@ bool ConstantParam::VisitCallExpr(const CallExpr * callExpr) { std::string callValue = getCallValue(valExpr); std::string paramName = i < functionDecl->getNumParams() ? functionDecl->getParamDecl(i)->getName().str() - : llvm::StringRef("###" + std::to_string(i)).str(); + : "###" + std::to_string(i); addToCallSet(functionDecl, i, paramName, callValue); } return true; @@ -299,7 +299,7 @@ bool ConstantParam::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr std::string callValue = getCallValue(valExpr); std::string paramName = i < constructorDecl->getNumParams() ? constructorDecl->getParamDecl(i)->getName().str() - : llvm::StringRef("###" + std::to_string(i)).str(); + : "###" + std::to_string(i); addToCallSet(constructorDecl, i, paramName, callValue); } return true; diff --git a/compilerplugins/clang/finalclasses.cxx b/compilerplugins/clang/finalclasses.cxx index 1c25b50afffe..4271a0a76f1b 100644 --- a/compilerplugins/clang/finalclasses.cxx +++ b/compilerplugins/clang/finalclasses.cxx @@ -70,15 +70,11 @@ private: void checkBase(QualType qt); }; -bool startsWith(const std::string& rStr, const char* pSubStr) { - return rStr.compare(0, strlen(pSubStr), pSubStr) == 0; -} - bool ignoreClass(StringRef s) { // ignore stuff in the standard library, and UNO stuff we can't touch. - if (startsWith(s.str(), "rtl::") || startsWith(s.str(), "sal::") || startsWith(s.str(), "com::sun::") - || startsWith(s.str(), "std::") || startsWith(s.str(), "boost::") + if (s.startswith("rtl::") || s.startswith("sal::") || s.startswith("com::sun::") + || s.startswith("std::") || s.startswith("boost::") || s == "OString" || s == "OUString" || s == "bad_alloc") { return true; @@ -136,8 +132,8 @@ bool FinalClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl) return true; SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)); - std::string filename = getFilenameOfLocation(spellingLocation).str(); - auto sourceLocation = filename.substr(strlen(SRCDIR)) + ":" + auto const filename = getFilenameOfLocation(spellingLocation); + auto sourceLocation = filename.substr(strlen(SRCDIR)).str() + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(spellingLocation)); definitionMap.insert( std::pair<std::string,std::string>(s, sourceLocation) ); return true; diff --git a/compilerplugins/clang/mergeclasses.cxx b/compilerplugins/clang/mergeclasses.cxx index 495cdf7010f1..0f0d73d709c2 100644 --- a/compilerplugins/clang/mergeclasses.cxx +++ b/compilerplugins/clang/mergeclasses.cxx @@ -80,15 +80,11 @@ public: bool VisitCXXRecordDecl( const CXXRecordDecl* decl); }; -bool startsWith(const std::string& rStr, const char* pSubStr) { - return rStr.compare(0, strlen(pSubStr), pSubStr) == 0; -} - bool ignoreClass(StringRef s) { // ignore stuff in the standard library, and UNO stuff we can't touch. - if (startsWith(s.str(), "rtl::") || startsWith(s.str(), "sal::") || startsWith(s.str(), "com::sun::") - || startsWith(s.str(), "std::") || startsWith(s.str(), "boost::") + if (s.startswith("rtl::") || s.startswith("sal::") || s.startswith("com::sun::") + || s.startswith("std::") || s.startswith("boost::") || s == "OString" || s == "OUString" || s == "bad_alloc") { return true; @@ -149,12 +145,12 @@ bool MergeClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl) if (decl->isThisDeclarationADefinition()) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)); - std::string filename = getFilenameOfLocation(spellingLocation).str(); + auto filename = getFilenameOfLocation(spellingLocation); filename = filename.substr(strlen(SRCDIR)); std::string s = decl->getQualifiedNameAsString(); if (ignoreClass(s)) return true; - definitionMap.insert( std::pair<std::string,std::string>(s, filename) ); + definitionMap.insert( std::pair<std::string,std::string>(s, filename.str()) ); for (auto it = decl->bases_begin(); it != decl->bases_end(); ++it) { const CXXBaseSpecifier spec = *it; diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index d0156cac44bb..564e81c442e7 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -296,12 +296,12 @@ void UseUniquePtr::CheckDeleteExpr(const FunctionDecl* functionDecl, const CXXDe } template<typename T> -bool any_equal(std::string const & needle, T first) { +bool any_equal(StringRef needle, T first) { return needle == first; } template<typename T, typename... Args> -bool any_equal(std::string const & needle, T first, Args... args) { +bool any_equal(StringRef needle, T first, Args... args) { return needle == first || any_equal(needle, args...); } @@ -500,18 +500,19 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C if (parentName == "ScBroadcastAreaSlot") return; // complicated - if (any_equal(parentName.str(), "SwFormatField", "FontPropertyBox", "SdFontPropertyBox", + if (any_equal(parentName, "SwFormatField", "FontPropertyBox", "SdFontPropertyBox", "SwHTMLParser", "PDFWriterImpl", "SbiParser", "DictionaryList", "SwGlossaryHdl", "SwGlossaryGroupDlg")) return; // ok - if (any_equal(parentName.str(), "SbTreeListBox")) + if (any_equal(parentName, "SbTreeListBox")) return; if (functionDecl->getIdentifier()) { - std::string name = functionDecl->getName().str(); + auto name = functionDecl->getName(); + SmallString<256> buf; if (!parentName.empty()) - name = std::string(parentName) + "::" + name; + name = (parentName + "::" + name).toStringRef(buf); // custom deleters if (name == "Proxy_free" || name == "s_free" || name == "binuno_proxy_free") |