bulbazord updated this revision to Diff 537451.
bulbazord added a comment.

Remove unneeded `else`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154534/new/

https://reviews.llvm.org/D154534

Files:
  lldb/source/Utility/StructuredData.cpp


Index: lldb/source/Utility/StructuredData.cpp
===================================================================
--- lldb/source/Utility/StructuredData.cpp
+++ lldb/source/Utility/StructuredData.cpp
@@ -104,33 +104,31 @@
 
 StructuredData::ObjectSP
 StructuredData::Object::GetObjectForDotSeparatedPath(llvm::StringRef path) {
-  if (this->GetType() == lldb::eStructuredDataTypeDictionary) {
+  if (GetType() == lldb::eStructuredDataTypeDictionary) {
     std::pair<llvm::StringRef, llvm::StringRef> match = path.split('.');
-    std::string key = match.first.str();
-    ObjectSP value = this->GetAsDictionary()->GetValueForKey(key);
-    if (value.get()) {
-      // Do we have additional words to descend?  If not, return the value
-      // we're at right now.
-      if (match.second.empty()) {
-        return value;
-      } else {
-        return value->GetObjectForDotSeparatedPath(match.second);
-      }
-    }
-    return ObjectSP();
+    llvm::StringRef key = match.first;
+    ObjectSP value = GetAsDictionary()->GetValueForKey(key);
+    if (!value)
+      return {};
+
+    // Do we have additional words to descend?  If not, return the value
+    // we're at right now.
+    if (match.second.empty())
+      return value;
+
+    return value->GetObjectForDotSeparatedPath(match.second);
   }
 
-  if (this->GetType() == lldb::eStructuredDataTypeArray) {
+  if (GetType() == lldb::eStructuredDataTypeArray) {
     std::pair<llvm::StringRef, llvm::StringRef> match = path.split('[');
-    if (match.second.empty()) {
+    if (match.second.empty())
       return this->shared_from_this();
-    }
-    errno = 0;
-    uint64_t val = strtoul(match.second.str().c_str(), nullptr, 10);
-    if (errno == 0) {
-      return this->GetAsArray()->GetItemAtIndex(val);
-    }
-    return ObjectSP();
+
+    uint64_t val = 0;
+    if (!llvm::to_integer(match.second, val, /* Base = */ 10))
+      return {};
+
+    return GetAsArray()->GetItemAtIndex(val);
   }
 
   return this->shared_from_this();


Index: lldb/source/Utility/StructuredData.cpp
===================================================================
--- lldb/source/Utility/StructuredData.cpp
+++ lldb/source/Utility/StructuredData.cpp
@@ -104,33 +104,31 @@
 
 StructuredData::ObjectSP
 StructuredData::Object::GetObjectForDotSeparatedPath(llvm::StringRef path) {
-  if (this->GetType() == lldb::eStructuredDataTypeDictionary) {
+  if (GetType() == lldb::eStructuredDataTypeDictionary) {
     std::pair<llvm::StringRef, llvm::StringRef> match = path.split('.');
-    std::string key = match.first.str();
-    ObjectSP value = this->GetAsDictionary()->GetValueForKey(key);
-    if (value.get()) {
-      // Do we have additional words to descend?  If not, return the value
-      // we're at right now.
-      if (match.second.empty()) {
-        return value;
-      } else {
-        return value->GetObjectForDotSeparatedPath(match.second);
-      }
-    }
-    return ObjectSP();
+    llvm::StringRef key = match.first;
+    ObjectSP value = GetAsDictionary()->GetValueForKey(key);
+    if (!value)
+      return {};
+
+    // Do we have additional words to descend?  If not, return the value
+    // we're at right now.
+    if (match.second.empty())
+      return value;
+
+    return value->GetObjectForDotSeparatedPath(match.second);
   }
 
-  if (this->GetType() == lldb::eStructuredDataTypeArray) {
+  if (GetType() == lldb::eStructuredDataTypeArray) {
     std::pair<llvm::StringRef, llvm::StringRef> match = path.split('[');
-    if (match.second.empty()) {
+    if (match.second.empty())
       return this->shared_from_this();
-    }
-    errno = 0;
-    uint64_t val = strtoul(match.second.str().c_str(), nullptr, 10);
-    if (errno == 0) {
-      return this->GetAsArray()->GetItemAtIndex(val);
-    }
-    return ObjectSP();
+
+    uint64_t val = 0;
+    if (!llvm::to_integer(match.second, val, /* Base = */ 10))
+      return {};
+
+    return GetAsArray()->GetItemAtIndex(val);
   }
 
   return this->shared_from_this();
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits]... Alex Langford via Phabricator via lldb-commits
    • [Lldb-com... Felipe de Azevedo Piovezan via Phabricator via lldb-commits
    • [Lldb-com... Alex Langford via Phabricator via lldb-commits
    • [Lldb-com... Alex Langford via Phabricator via lldb-commits
    • [Lldb-com... Felipe de Azevedo Piovezan via Phabricator via lldb-commits
    • [Lldb-com... Med Ismail Bennani via Phabricator via lldb-commits
    • [Lldb-com... Alex Langford via Phabricator via lldb-commits
    • [Lldb-com... Alex Langford via Phabricator via lldb-commits
    • [Lldb-com... Alex Langford via Phabricator via lldb-commits

Reply via email to