[Lldb-commits] [lldb] r246609 - Simplify find_first_of & find_last_of on single char.

Bruce Mitchener via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 1 16:57:18 PDT 2015


Author: brucem
Date: Tue Sep  1 18:57:17 2015
New Revision: 246609

URL: http://llvm.org/viewvc/llvm-project?rev=246609&view=rev
Log:
Simplify find_first_of & find_last_of on single char.

Summary:
When calling find_first_of and find_last_of on a single character,
we can instead just call find / rfind and make our intent more
clear.

Reviewers: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D12518

Modified:
    lldb/trunk/source/Core/FormatEntity.cpp
    lldb/trunk/source/Host/common/FileSpec.cpp
    lldb/trunk/source/Host/common/ThisThread.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
    lldb/trunk/source/Utility/UriParser.cpp
    lldb/trunk/tools/lldb-mi/MICmdArgValFile.cpp
    lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp
    lldb/trunk/tools/lldb-mi/MICmdArgValString.cpp
    lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp
    lldb/trunk/tools/lldb-mi/MICmdCmdBreak.cpp

Modified: lldb/trunk/source/Core/FormatEntity.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatEntity.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatEntity.cpp (original)
+++ lldb/trunk/source/Core/FormatEntity.cpp Tue Sep  1 18:57:17 2015
@@ -2424,10 +2424,10 @@ FormatEntity::ExtractVariableInfo (llvm:
     variable_name = llvm::StringRef();
     variable_format = llvm::StringRef();
 
-    const size_t paren_pos = format_str.find_first_of('}');
+    const size_t paren_pos = format_str.find('}');
     if (paren_pos != llvm::StringRef::npos)
     {
-        const size_t percent_pos = format_str.find_first_of('%');
+        const size_t percent_pos = format_str.find('%');
         if (percent_pos < paren_pos)
         {
             if (percent_pos > 0)

Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Tue Sep  1 18:57:17 2015
@@ -107,7 +107,7 @@ FileSpec::ResolveUsername (llvm::SmallVe
         return;
     
     llvm::StringRef path_str(path.data(), path.size());
-    size_t slash_pos = path_str.find_first_of("/", 1);
+    size_t slash_pos = path_str.find('/', 1);
     if (slash_pos == 1 || path.size() == 1)
     {
         // A path of ~/ resolves to the current user's home dir

Modified: lldb/trunk/source/Host/common/ThisThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/ThisThread.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/ThisThread.cpp (original)
+++ lldb/trunk/source/Host/common/ThisThread.cpp Tue Sep  1 18:57:17 2015
@@ -37,7 +37,7 @@ ThisThread::SetName(llvm::StringRef name
         {
             // We're still too long.  Since this is a dotted component, use everything after the last
             // dot, up to a maximum of |length| characters.
-            std::string::size_type last_dot = truncated_name.find_last_of(".");
+            std::string::size_type last_dot = truncated_name.rfind('.');
             if (last_dot != std::string::npos)
                 begin = last_dot + 1;
 

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp Tue Sep  1 18:57:17 2015
@@ -230,7 +230,7 @@ AppleObjCTypeEncodingParser::BuildObjCOb
     
     if (for_expression && !name.empty())
     {
-        size_t less_than_pos = name.find_first_of('<');
+        size_t less_than_pos = name.find('<');
         
         if (less_than_pos != std::string::npos)
         {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp Tue Sep  1 18:57:17 2015
@@ -609,12 +609,12 @@ RSModuleDescriptor::ParseRSInfo()
         std::string info((const char *)buffer->GetBytes());
 
         std::vector<std::string> info_lines;
-        size_t lpos = info.find_first_of("\n");
+        size_t lpos = info.find('\n');
         while (lpos != std::string::npos)
         {
             info_lines.push_back(info.substr(0, lpos));
             info = info.substr(lpos + 1);
-            lpos = info.find_first_of("\n");
+            lpos = info.find('\n');
         }
         size_t offset = 0;
         while (offset < info_lines.size())

Modified: lldb/trunk/source/Utility/UriParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/UriParser.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/source/Utility/UriParser.cpp (original)
+++ lldb/trunk/source/Utility/UriParser.cpp Tue Sep  1 18:57:17 2015
@@ -40,7 +40,7 @@ UriParser::Parse(const std::string& uri,
     // Extract path.
     tmp_scheme = uri.substr(0, pos);
     auto host_pos = pos + strlen(kSchemeSep);
-    auto path_pos = uri.find_first_of("/", host_pos);
+    auto path_pos = uri.find('/', host_pos);
     if (path_pos != std::string::npos)
         tmp_path = uri.substr(path_pos);
     else

Modified: lldb/trunk/tools/lldb-mi/MICmdArgValFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgValFile.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgValFile.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgValFile.cpp Tue Sep  1 18:57:17 2015
@@ -142,8 +142,8 @@ CMICmdArgValFile::IsFilePath(const CMIUt
     if (vrFileNamePath.empty())
         return false;
 
-    const bool bHavePosSlash = (vrFileNamePath.find_first_of("/") != std::string::npos);
-    const bool bHaveBckSlash = (vrFileNamePath.find_first_of("\\") != std::string::npos);
+    const bool bHavePosSlash = (vrFileNamePath.find('/') != std::string::npos);
+    const bool bHaveBckSlash = (vrFileNamePath.find('\\') != std::string::npos);
 
     // Look for --someLongOption
     size_t nPos = vrFileNamePath.find("--");
@@ -152,13 +152,13 @@ CMICmdArgValFile::IsFilePath(const CMIUt
         return false;
 
     // Look for -f type short parameters
-    nPos = vrFileNamePath.find_first_of("-");
+    nPos = vrFileNamePath.find('-');
     const bool bShort = (nPos == 0);
     if (bShort)
         return false;
 
     // Look for i1 i2 i3....
-    nPos = vrFileNamePath.find_first_of("i");
+    nPos = vrFileNamePath.find('i');
     const bool bFoundI1 = ((nPos == 0) && (::isdigit(vrFileNamePath[1])));
     if (bFoundI1)
         return false;

Modified: lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp Tue Sep  1 18:57:17 2015
@@ -249,8 +249,8 @@ CMICmdArgValOptionLong::ExtractExpectedO
 bool
 CMICmdArgValOptionLong::IsArgLongOption(const CMIUtilString &vrTxt) const
 {
-    const bool bHavePosSlash = (vrTxt.find_first_of("/") != std::string::npos);
-    const bool bHaveBckSlash = (vrTxt.find_first_of("\\") != std::string::npos);
+    const bool bHavePosSlash = (vrTxt.find('/') != std::string::npos);
+    const bool bHaveBckSlash = (vrTxt.find('\\') != std::string::npos);
     if (bHavePosSlash || bHaveBckSlash)
         return false;
 

Modified: lldb/trunk/tools/lldb-mi/MICmdArgValString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgValString.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgValString.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgValString.cpp Tue Sep  1 18:57:17 2015
@@ -220,8 +220,8 @@ CMICmdArgValString::IsStringArgSingleTex
     if (!m_bHandleDirPaths)
     {
         // Look for directory file paths, if found reject
-        const bool bHavePosSlash = (vrTxt.find_first_of("/") != std::string::npos);
-        const bool bHaveBckSlash = (vrTxt.find_first_of("\\") != std::string::npos);
+        const bool bHavePosSlash = (vrTxt.find('/') != std::string::npos);
+        const bool bHaveBckSlash = (vrTxt.find('\\') != std::string::npos);
         if (bHavePosSlash || bHaveBckSlash)
             return false;
     }

Modified: lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp Tue Sep  1 18:57:17 2015
@@ -117,7 +117,7 @@ bool
 CMICmdArgValThreadGrp::IsArgThreadGrp(const CMIUtilString &vrTxt) const
 {
     // Look for i1 i2 i3....
-    const MIint nPos = vrTxt.find_first_of("i");
+    const MIint nPos = vrTxt.find('i');
     if (nPos != 0)
         return false;
 

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdBreak.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdBreak.cpp?rev=246609&r1=246608&r2=246609&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdBreak.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdBreak.cpp Tue Sep  1 18:57:17 2015
@@ -118,10 +118,10 @@ static size_t findFileSeparatorPos(const
 {
     // Full paths in windows can have ':' after a drive letter, so we
     // search backwards, taking care to skip C++ namespace tokens '::'.
-    size_t n = x.find_last_of(':');
+    size_t n = x.rfind(':');
     while (n != std::string::npos && n > 1 && x[n-1] == ':')
     {
-        n = x.find_last_of(':', n - 2);
+        n = x.rfind(':', n - 2);
     }
     return n;
 }




More information about the lldb-commits mailing list