[PATCH] D151079: [llvm][ADT] Change isEqual for DenseMapInfo<std::variant<...>>

Kadir Cetinkaya via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 22 04:39:27 PDT 2023


kadircet created this revision.
kadircet added a reviewer: IncludeGuardian.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Defer to DenseMapInfo<T>::isEqual instead of operator==(T,T).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151079

Files:
  llvm/include/llvm/ADT/DenseMapInfo.h
  llvm/unittests/ADT/DenseMapTest.cpp


Index: llvm/unittests/ADT/DenseMapTest.cpp
===================================================================
--- llvm/unittests/ADT/DenseMapTest.cpp
+++ llvm/unittests/ADT/DenseMapTest.cpp
@@ -736,5 +736,7 @@
   EXPECT_THAT(Map, testing::SizeIs(2));
   EXPECT_NE(DenseMapInfo<variant>::getHashValue(Keys[0]),
             DenseMapInfo<variant>::getHashValue(Keys[1]));
+  EXPECT_TRUE(DenseMapInfo<variant>::isEqual(Keys[0], Keys[0]));
+  EXPECT_FALSE(DenseMapInfo<variant>::isEqual(Keys[0], Keys[1]));
 }
 } // namespace
Index: llvm/include/llvm/ADT/DenseMapInfo.h
===================================================================
--- llvm/include/llvm/ADT/DenseMapInfo.h
+++ llvm/include/llvm/ADT/DenseMapInfo.h
@@ -318,8 +318,19 @@
   }
 
   static bool isEqual(const Variant &LHS, const Variant &RHS) {
-    return LHS == RHS;
-  }
+    return LHS.index() == RHS.index() && std::visit(EqVisitor{}, LHS, RHS);
+  }
+
+ private:
+  struct EqVisitor {
+    template <typename T, typename U>
+    bool operator()(const T &LHS, const U &RHS) const {
+      return false;
+    }
+    template <typename T> bool operator()(const T &LHS, const T &RHS) const {
+      return DenseMapInfo<T>::isEqual(LHS, RHS);
+    }
+  };
 };
 } // end namespace llvm
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151079.524243.patch
Type: text/x-patch
Size: 1253 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230522/614c370b/attachment.bin>


More information about the llvm-commits mailing list