[Lldb-commits] [lldb] ef748b5 - [lldb] NFC: Use early exit in ArchSpec::IsEqualTo

Fred Riss via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 27 14:12:14 PDT 2020


Author: Fred Riss
Date: 2020-07-27T14:12:02-07:00
New Revision: ef748b58d3b3edfaf0278d454cb30f7816c04aee

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

LOG: [lldb] NFC: Use early exit in ArchSpec::IsEqualTo

Added: 
    

Modified: 
    lldb/source/Utility/ArchSpec.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp
index a77ae8633070..cd382a322da7 100644
--- a/lldb/source/Utility/ArchSpec.cpp
+++ b/lldb/source/Utility/ArchSpec.cpp
@@ -1010,77 +1010,70 @@ static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs,
 bool ArchSpec::IsEqualTo(const ArchSpec &rhs, bool exact_match) const {
   // explicitly ignoring m_distribution_id in this method.
 
-  if (GetByteOrder() != rhs.GetByteOrder())
+  if (GetByteOrder() != rhs.GetByteOrder() ||
+      !cores_match(GetCore(), rhs.GetCore(), true, exact_match))
     return false;
 
-  const ArchSpec::Core lhs_core = GetCore();
-  const ArchSpec::Core rhs_core = rhs.GetCore();
+  const llvm::Triple &lhs_triple = GetTriple();
+  const llvm::Triple &rhs_triple = rhs.GetTriple();
+
+  const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
+  const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
+  if (lhs_triple_vendor != rhs_triple_vendor) {
+    const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
+    const bool lhs_vendor_specified = TripleVendorWasSpecified();
+    // Both architectures had the vendor specified, so if they aren't equal
+    // then we return false
+    if (rhs_vendor_specified && lhs_vendor_specified)
+      return false;
 
-  const bool core_match = cores_match(lhs_core, rhs_core, true, exact_match);
-
-  if (core_match) {
-    const llvm::Triple &lhs_triple = GetTriple();
-    const llvm::Triple &rhs_triple = rhs.GetTriple();
-
-    const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
-    const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
-    if (lhs_triple_vendor != rhs_triple_vendor) {
-      const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
-      const bool lhs_vendor_specified = TripleVendorWasSpecified();
-      // Both architectures had the vendor specified, so if they aren't equal
-      // then we return false
-      if (rhs_vendor_specified && lhs_vendor_specified)
-        return false;
-
-      // Only fail if both vendor types are not unknown
-      if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
-          rhs_triple_vendor != llvm::Triple::UnknownVendor)
-        return false;
-    }
+    // Only fail if both vendor types are not unknown
+    if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
+        rhs_triple_vendor != llvm::Triple::UnknownVendor)
+      return false;
+  }
 
-    const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
-    const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
-    const llvm::Triple::EnvironmentType lhs_triple_env =
+  const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
+  const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
+  const llvm::Triple::EnvironmentType lhs_triple_env =
       lhs_triple.getEnvironment();
-    const llvm::Triple::EnvironmentType rhs_triple_env =
+  const llvm::Triple::EnvironmentType rhs_triple_env =
       rhs_triple.getEnvironment();
 
-    if (!exact_match) {
-      // x86_64-apple-ios-macabi, x86_64-apple-macosx are compatible, no match.
-      if ((lhs_triple_os == llvm::Triple::IOS &&
-           lhs_triple_env == llvm::Triple::MacABI &&
-           rhs_triple_os == llvm::Triple::MacOSX) ||
-          (lhs_triple_os == llvm::Triple::MacOSX &&
-           rhs_triple_os == llvm::Triple::IOS &&
-           rhs_triple_env == llvm::Triple::MacABI))
-        return true;
-    }
-
-    if (lhs_triple_os != rhs_triple_os) {
-      const bool rhs_os_specified = rhs.TripleOSWasSpecified();
-      const bool lhs_os_specified = TripleOSWasSpecified();
-      // Both architectures had the OS specified, so if they aren't equal then
-      // we return false
-      if (rhs_os_specified && lhs_os_specified)
-        return false;
-
-      // Only fail if both os types are not unknown
-      if (lhs_triple_os != llvm::Triple::UnknownOS &&
-          rhs_triple_os != llvm::Triple::UnknownOS)
-        return false;
-    }
+  if (!exact_match) {
+    // x86_64-apple-ios-macabi, x86_64-apple-macosx are compatible, no match.
+    if ((lhs_triple_os == llvm::Triple::IOS &&
+         lhs_triple_env == llvm::Triple::MacABI &&
+         rhs_triple_os == llvm::Triple::MacOSX) ||
+        (lhs_triple_os == llvm::Triple::MacOSX &&
+         rhs_triple_os == llvm::Triple::IOS &&
+         rhs_triple_env == llvm::Triple::MacABI))
+      return true;
+  }
 
-    // x86_64-apple-ios-macabi and x86_64-apple-ios are not compatible.
-    if (lhs_triple_os == llvm::Triple::IOS &&
-        rhs_triple_os == llvm::Triple::IOS &&
-        (lhs_triple_env == llvm::Triple::MacABI ||
-         rhs_triple_env == llvm::Triple::MacABI) &&
-        lhs_triple_env != rhs_triple_env)
+  if (lhs_triple_os != rhs_triple_os) {
+    const bool rhs_os_specified = rhs.TripleOSWasSpecified();
+    const bool lhs_os_specified = TripleOSWasSpecified();
+    // Both architectures had the OS specified, so if they aren't equal then
+    // we return false
+    if (rhs_os_specified && lhs_os_specified)
       return false;
 
-    return IsCompatibleEnvironment(lhs_triple_env, rhs_triple_env);
+    // Only fail if both os types are not unknown
+    if (lhs_triple_os != llvm::Triple::UnknownOS &&
+        rhs_triple_os != llvm::Triple::UnknownOS)
+      return false;
   }
-  return false;
+
+  // x86_64-apple-ios-macabi and x86_64-apple-ios are not compatible.
+  if (lhs_triple_os == llvm::Triple::IOS &&
+      rhs_triple_os == llvm::Triple::IOS &&
+      (lhs_triple_env == llvm::Triple::MacABI ||
+       rhs_triple_env == llvm::Triple::MacABI) &&
+      lhs_triple_env != rhs_triple_env)
+    return false;
+
+  return IsCompatibleEnvironment(lhs_triple_env, rhs_triple_env);
 }
 
 void ArchSpec::UpdateCore() {


        


More information about the lldb-commits mailing list