[flang-commits] [flang] 20f0f15 - Use StringRef::contains (NFC)

Kazu Hirata via flang-commits flang-commits at lists.llvm.org
Sun Aug 28 23:29:24 PDT 2022


Author: Kazu Hirata
Date: 2022-08-28T23:29:02-07:00
New Revision: 20f0f15a4055d66fae494fc79bd76f14dee3954f

URL: https://github.com/llvm/llvm-project/commit/20f0f15a4055d66fae494fc79bd76f14dee3954f
DIFF: https://github.com/llvm/llvm-project/commit/20f0f15a4055d66fae494fc79bd76f14dee3954f.diff

LOG: Use StringRef::contains (NFC)

Added: 
    

Modified: 
    bolt/include/bolt/Profile/DataReader.h
    bolt/lib/Profile/DataAggregator.cpp
    clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
    clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
    flang/lib/Lower/ConvertExpr.cpp
    flang/lib/Lower/IO.cpp

Removed: 
    


################################################################################
diff  --git a/bolt/include/bolt/Profile/DataReader.h b/bolt/include/bolt/Profile/DataReader.h
index 4253fc1d66973..cf6d24c67f112 100644
--- a/bolt/include/bolt/Profile/DataReader.h
+++ b/bolt/include/bolt/Profile/DataReader.h
@@ -449,7 +449,7 @@ class DataReader : public ProfileReaderBase {
   bool usesEvent(StringRef Name) const {
     for (auto I = EventNames.begin(), E = EventNames.end(); I != E; ++I) {
       StringRef Event = I->getKey();
-      if (Event.find(Name) != StringRef::npos)
+      if (Event.contains(Name))
         return true;
     }
     return false;

diff  --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index 678e69b97a7c1..6ac315e972431 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -1158,7 +1158,7 @@ ErrorOr<DataAggregator::PerfMemSample> DataAggregator::parseMemSample() {
   ErrorOr<StringRef> Event = parseString(FieldSeparator);
   if (std::error_code EC = Event.getError())
     return EC;
-  if (Event.get().find("mem-loads") == StringRef::npos) {
+  if (!Event.get().contains("mem-loads")) {
     consumeRestOfLine();
     return Res;
   }

diff  --git a/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp b/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
index 9e2c2cdbf8175..7f7af7069c418 100644
--- a/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
+++ b/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
@@ -206,7 +206,7 @@ std::string getShortestQualifiedNameInNamespace(llvm::StringRef DeclName,
                                                 llvm::StringRef NsName) {
   DeclName = DeclName.ltrim(':');
   NsName = NsName.ltrim(':');
-  if (DeclName.find(':') == llvm::StringRef::npos)
+  if (!DeclName.contains(':'))
     return std::string(DeclName);
 
   auto NsNameSplitted = splitSymbolName(NsName);

diff  --git a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
index 05ef855de7e71..cd221f2d938b9 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
@@ -68,9 +68,8 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
     PtrToContainer = true;
   }
   const llvm::StringRef IneffContName = IneffCont->getName();
-  const bool Unordered =
-      IneffContName.find("unordered") != llvm::StringRef::npos;
-  const bool Maplike = IneffContName.find("map") != llvm::StringRef::npos;
+  const bool Unordered = IneffContName.contains("unordered");
+  const bool Maplike = IneffContName.contains("map");
 
   // Store if the key type of the container is compatible with the value
   // that is searched for.
@@ -84,8 +83,7 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
     const Expr *Arg = AlgCall->getArg(3);
     const QualType AlgCmp =
         Arg->getType().getUnqualifiedType().getCanonicalType();
-    const unsigned CmpPosition =
-        (IneffContName.find("map") == llvm::StringRef::npos) ? 1 : 2;
+    const unsigned CmpPosition = IneffContName.contains("map") ? 2 : 1;
     const QualType ContainerCmp = IneffCont->getTemplateArgs()[CmpPosition]
                                       .getAsType()
                                       .getUnqualifiedType()

diff  --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index b50670e1e4419..59156bb9332fe 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -1497,7 +1497,7 @@ class ScalarExprLowering {
   /// NaN strings as well. \p s is assumed to not contain any spaces.
   static llvm::APFloat consAPFloat(const llvm::fltSemantics &fsem,
                                    llvm::StringRef s) {
-    assert(s.find(' ') == llvm::StringRef::npos);
+    assert(!s.contains(' '));
     if (s.compare_insensitive("-inf") == 0)
       return llvm::APFloat::getInf(fsem, /*negative=*/true);
     if (s.compare_insensitive("inf") == 0 || s.compare_insensitive("+inf") == 0)

diff  --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 8c534f9b8ba33..00fa17e4508dc 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -1417,8 +1417,7 @@ lowerReferenceAsStringSelect(Fortran::lower::AbstractConverter &converter,
     mlir::Value stringRef;
     mlir::Value stringLen;
     if (eval->isA<Fortran::parser::FormatStmt>()) {
-      assert(text.find('(') != llvm::StringRef::npos &&
-             "FORMAT is unexpectedly ill-formed");
+      assert(text.contains('(') && "FORMAT is unexpectedly ill-formed");
       // This is a format statement, so extract the spec from the text.
       std::tuple<mlir::Value, mlir::Value, mlir::Value> stringLit =
           lowerSourceTextAsStringLit(converter, loc, text, strTy, lenTy);


        


More information about the flang-commits mailing list