[libc-commits] [libc] b8f89b8 - Use StringRef::{starts, ends}_with (NFC)

Kazu Hirata via libc-commits libc-commits at lists.llvm.org
Sat Dec 16 15:02:26 PST 2023


Author: Kazu Hirata
Date: 2023-12-16T15:02:17-08:00
New Revision: b8f89b84bc26c46a5a10d01eb5414fbde3c8700a

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

LOG: Use StringRef::{starts,ends}_with (NFC)

This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.

Added: 
    

Modified: 
    clang-tools-extra/clangd/index/remote/server/Server.cpp
    clang/test/Index/recursive-cxx-member-calls.cpp
    libc/utils/HdrGen/Generator.cpp
    mlir/examples/toy/Ch2/toyc.cpp
    mlir/examples/toy/Ch3/toyc.cpp
    mlir/examples/toy/Ch4/toyc.cpp
    mlir/examples/toy/Ch5/toyc.cpp
    mlir/examples/toy/Ch6/toyc.cpp
    mlir/examples/toy/Ch7/toyc.cpp
    openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
    openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index e108d4d0b057ba..4ef3ab6f9af9c2 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -451,7 +451,7 @@ std::unique_ptr<Logger> makeLogger(llvm::StringRef LogPrefix,
       void log(Level L, const char *Fmt,
                const llvm::formatv_object_base &Message) override {
         if (Context::current().get(CurrentRequest) == nullptr ||
-            llvm::StringRef(Fmt).startswith("[public]"))
+            llvm::StringRef(Fmt).starts_with("[public]"))
           return StreamLogger::log(L, Fmt, Message);
         if (L >= Error)
           return StreamLogger::log(L, Fmt,

diff  --git a/clang/test/Index/recursive-cxx-member-calls.cpp b/clang/test/Index/recursive-cxx-member-calls.cpp
index be908c506e7476..48fc8f14544c48 100644
--- a/clang/test/Index/recursive-cxx-member-calls.cpp
+++ b/clang/test/Index/recursive-cxx-member-calls.cpp
@@ -99,7 +99,7 @@ using namespace clang;
 
 AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
   llvm::StringRef AttrName = Name->getName();
-  if (AttrName.startswith("__") && AttrName.endswith("__"))
+  if (AttrName.starts_with("__") && AttrName.ends_with("__"))
     AttrName = AttrName.substr(2, AttrName.size() - 4);
 
   return llvm::StringSwitch < AttributeList::Kind > (AttrName)

diff  --git a/libc/utils/HdrGen/Generator.cpp b/libc/utils/HdrGen/Generator.cpp
index 24d22680fe525b..3bcf005adda74f 100644
--- a/libc/utils/HdrGen/Generator.cpp
+++ b/libc/utils/HdrGen/Generator.cpp
@@ -57,7 +57,7 @@ void Generator::parseCommandArgs(llvm::StringRef ArgStr, ArgVector &Args) {
   ArgStr.split(Args, ",");
   for (llvm::StringRef &A : Args) {
     A = A.trim(' ');
-    if (A.startswith(ParamNamePrefix) && A.endswith(ParamNameSuffix)) {
+    if (A.starts_with(ParamNamePrefix) && A.ends_with(ParamNameSuffix)) {
       A = A.drop_front(ParamNamePrefixSize).drop_back(ParamNameSuffixSize);
       A = ArgMap[std::string(A)];
     }
@@ -80,7 +80,7 @@ void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
     Content = P.second;
 
     llvm::StringRef Line = P.first.trim(' ');
-    if (Line.startswith(CommandPrefix)) {
+    if (Line.starts_with(CommandPrefix)) {
       Line = Line.drop_front(CommandPrefixSize);
 
       P = Line.split("(");
@@ -107,7 +107,7 @@ void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
       Command::ErrorReporter Reporter(
           llvm::SMLoc::getFromPointer(CommandName.data()), SrcMgr);
       Cmd->run(OS, Args, StdHeader, Records, Reporter);
-    } else if (!Line.startswith(CommentPrefix)) {
+    } else if (!Line.starts_with(CommentPrefix)) {
       // There is no comment or command on this line so we just write it as is.
       OS << P.first << "\n";
     }

diff  --git a/mlir/examples/toy/Ch2/toyc.cpp b/mlir/examples/toy/Ch2/toyc.cpp
index fa431972e211ef..e33b49b41c5a1d 100644
--- a/mlir/examples/toy/Ch2/toyc.cpp
+++ b/mlir/examples/toy/Ch2/toyc.cpp
@@ -78,7 +78,7 @@ int dumpMLIR() {
 
   // Handle '.toy' input to the compiler.
   if (inputType != InputType::MLIR &&
-      !llvm::StringRef(inputFilename).endswith(".mlir")) {
+      !llvm::StringRef(inputFilename).ends_with(".mlir")) {
     auto moduleAST = parseInputFile(inputFilename);
     if (!moduleAST)
       return 6;

diff  --git a/mlir/examples/toy/Ch3/toyc.cpp b/mlir/examples/toy/Ch3/toyc.cpp
index 8c27a7af97a002..c2c5f1fe1ba17b 100644
--- a/mlir/examples/toy/Ch3/toyc.cpp
+++ b/mlir/examples/toy/Ch3/toyc.cpp
@@ -82,7 +82,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
              mlir::OwningOpRef<mlir::ModuleOp> &module) {
   // Handle '.toy' input to the compiler.
   if (inputType != InputType::MLIR &&
-      !llvm::StringRef(inputFilename).endswith(".mlir")) {
+      !llvm::StringRef(inputFilename).ends_with(".mlir")) {
     auto moduleAST = parseInputFile(inputFilename);
     if (!moduleAST)
       return 6;

diff  --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp
index d35e07cf3f20ba..a1534ed30341c8 100644
--- a/mlir/examples/toy/Ch4/toyc.cpp
+++ b/mlir/examples/toy/Ch4/toyc.cpp
@@ -83,7 +83,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
              mlir::OwningOpRef<mlir::ModuleOp> &module) {
   // Handle '.toy' input to the compiler.
   if (inputType != InputType::MLIR &&
-      !llvm::StringRef(inputFilename).endswith(".mlir")) {
+      !llvm::StringRef(inputFilename).ends_with(".mlir")) {
     auto moduleAST = parseInputFile(inputFilename);
     if (!moduleAST)
       return 6;

diff  --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp
index e0742b8e992b31..4eb6fdeeafa1dd 100644
--- a/mlir/examples/toy/Ch5/toyc.cpp
+++ b/mlir/examples/toy/Ch5/toyc.cpp
@@ -88,7 +88,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
              mlir::OwningOpRef<mlir::ModuleOp> &module) {
   // Handle '.toy' input to the compiler.
   if (inputType != InputType::MLIR &&
-      !llvm::StringRef(inputFilename).endswith(".mlir")) {
+      !llvm::StringRef(inputFilename).ends_with(".mlir")) {
     auto moduleAST = parseInputFile(inputFilename);
     if (!moduleAST)
       return 6;

diff  --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp
index fe2137cfdfbfc6..534f0d60e80092 100644
--- a/mlir/examples/toy/Ch6/toyc.cpp
+++ b/mlir/examples/toy/Ch6/toyc.cpp
@@ -112,7 +112,7 @@ int loadMLIR(mlir::MLIRContext &context,
              mlir::OwningOpRef<mlir::ModuleOp> &module) {
   // Handle '.toy' input to the compiler.
   if (inputType != InputType::MLIR &&
-      !llvm::StringRef(inputFilename).endswith(".mlir")) {
+      !llvm::StringRef(inputFilename).ends_with(".mlir")) {
     auto moduleAST = parseInputFile(inputFilename);
     if (!moduleAST)
       return 6;

diff  --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp
index d4cc8e7279d3ba..e4af0a3a3dce10 100644
--- a/mlir/examples/toy/Ch7/toyc.cpp
+++ b/mlir/examples/toy/Ch7/toyc.cpp
@@ -112,7 +112,7 @@ int loadMLIR(mlir::MLIRContext &context,
              mlir::OwningOpRef<mlir::ModuleOp> &module) {
   // Handle '.toy' input to the compiler.
   if (inputType != InputType::MLIR &&
-      !llvm::StringRef(inputFilename).endswith(".mlir")) {
+      !llvm::StringRef(inputFilename).ends_with(".mlir")) {
     auto moduleAST = parseInputFile(inputFilename);
     if (!moduleAST)
       return 6;

diff  --git a/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h b/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
index ab6c457fba7864..716b0ad7843310 100644
--- a/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
+++ b/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
@@ -290,7 +290,7 @@ struct GenericKernelTy {
   /// Return true if this kernel is a constructor or destructor.
   bool isCtorOrDtor() const {
     // TODO: This is not a great solution and should be revisited.
-    return StringRef(Name).endswith("tor");
+    return StringRef(Name).ends_with("tor");
   }
 
   /// Get the kernel image.

diff  --git a/openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp b/openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
index 7bad411b9d8e3b..a2ccf8446ba77f 100644
--- a/openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
@@ -1304,7 +1304,7 @@ struct CUDAPluginTy final : public GenericPluginTy {
 
       StringRef ArchStr(Info->Arch);
       StringRef PrefixStr("sm_");
-      if (!ArchStr.startswith(PrefixStr))
+      if (!ArchStr.starts_with(PrefixStr))
         return Plugin::error("Unrecognized image arch %s", ArchStr.data());
 
       int32_t ImageMajor = ArchStr[PrefixStr.size() + 0] - '0';


        


More information about the libc-commits mailing list