Author: Benjamin Kramer
Date: 2020-03-31T21:01:09+02:00
New Revision: e8f13f4f62f52067cadb55f3c746ccf9d26ee2ce

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

LOG: Replace std::string::find == 0 with StringRef::startswith

This is both more readable and faster. Found by clang-tidy's
abseil-string-find-startswith.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Arch/AArch64.cpp
    clang/unittests/Analysis/CloneDetectionTest.cpp
    lldb/source/Core/Module.cpp
    
lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
    lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/source/Symbol/Variable.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index dc31a5ab7b0f..b21cfac6e7ed 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -140,7 +140,8 @@ getAArch64MicroArchFeaturesFromMtune(const Driver &D, 
StringRef Mtune,
   // Handle CPU name is 'native'.
   if (MtuneLowerCase == "native")
     MtuneLowerCase = std::string(llvm::sys::getHostCPUName());
-  if (MtuneLowerCase == "cyclone" || MtuneLowerCase.find("apple") == 0) {
+  if (MtuneLowerCase == "cyclone" ||
+      StringRef(MtuneLowerCase).startswith("apple")) {
     Features.push_back("+zcm");
     Features.push_back("+zcz");
   }

diff  --git a/clang/unittests/Analysis/CloneDetectionTest.cpp 
b/clang/unittests/Analysis/CloneDetectionTest.cpp
index 03b63c400434..e09d0733f044 100644
--- a/clang/unittests/Analysis/CloneDetectionTest.cpp
+++ b/clang/unittests/Analysis/CloneDetectionTest.cpp
@@ -42,7 +42,7 @@ class NoBarFunctionConstraint {
           for (const StmtSequence &Arg : {A, B}) {
             if (const auto *D =
                     dyn_cast<const FunctionDecl>(Arg.getContainingDecl())) {
-              if (D->getNameAsString().find("bar") == 0)
+              if (StringRef(D->getNameAsString()).startswith("bar"))
                 return false;
             }
           }

diff  --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index cff74dc9d518..fefc23a9b1c5 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1414,7 +1414,7 @@ void Module::SetSymbolFileFileSpec(const FileSpec &file) {
         if (FileSystem::Instance().IsDirectory(file)) {
           std::string new_path(file.GetPath());
           std::string old_path(obj_file->GetFileSpec().GetPath());
-          if (old_path.find(new_path) == 0) {
+          if (llvm::StringRef(old_path).startswith(new_path)) {
             // We specified the same bundle as the symbol file that we already
             // have
             return;

diff  --git 
a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp 
b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 47c7ae8c8d63..83cf9f8bd269 100644
--- 
a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ 
b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -88,7 +88,7 @@ ObjectContainerBSDArchive::Object::Extract(const 
DataExtractor &data,
     return LLDB_INVALID_OFFSET;
 
   str.assign((const char *)data.GetData(&offset, 16), 16);
-  if (str.find("#1/") == 0) {
+  if (llvm::StringRef(str).startswith("#1/")) {
     // If the name is longer than 16 bytes, or contains an embedded space then
     // it will use this format where the length of the name is here and the
     // name characters are after this header.

diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index f5c84c6a6151..5044bed309dc 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5140,10 +5140,10 @@ uint32_t 
ObjectFileMachO::GetDependentModules(FileSpecList &files) {
       std::string loader_path("@loader_path");
       std::string executable_path("@executable_path");
       for (auto &rpath : rpath_paths) {
-        if (rpath.find(loader_path) == 0) {
+        if (llvm::StringRef(rpath).startswith(loader_path)) {
           rpath.erase(0, loader_path.size());
           rpath.insert(0, this_file_spec.GetDirectory().GetCString());
-        } else if (rpath.find(executable_path) == 0) {
+        } else if (llvm::StringRef(rpath).startswith(executable_path)) {
           rpath.erase(0, executable_path.size());
           rpath.insert(0, this_file_spec.GetDirectory().GetCString());
         }

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 72907a95f3ab..a3c19f71ce69 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4418,7 +4418,7 @@ bool ParseRegisters(XMLNode feature_node, 
GdbServerTargetInfo &target_info,
         });
 
         if (!gdb_type.empty() && !(encoding_set || format_set)) {
-          if (gdb_type.find("int") == 0) {
+          if (llvm::StringRef(gdb_type).startswith("int")) {
             reg_info.format = eFormatHex;
             reg_info.encoding = eEncodingUint;
           } else if (gdb_type == "data_ptr" || gdb_type == "code_ptr") {

diff  --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index f1533ef6d4b3..6c18ef15e1a2 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -529,7 +529,7 @@ static void PrivateAutoCompleteMembers(
           i, member_name, nullptr, nullptr, nullptr);
 
       if (partial_member_name.empty() ||
-          member_name.find(partial_member_name) == 0) {
+          llvm::StringRef(member_name).startswith(partial_member_name)) {
         if (member_name == partial_member_name) {
           PrivateAutoComplete(
               frame, partial_path,


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to