Add a helper useful when mapping from a map element to its hash node.
authorChris Lattner <sabre@nondot.org>
Sun, 30 Sep 2007 08:31:46 +0000 (08:31 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 30 Sep 2007 08:31:46 +0000 (08:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42480 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringMap.h

index 72108e97e4fb54d8b958d2521331cafe79831084..fecd61ead1b94370f58cf6757c045f14beaad5cc 100644 (file)
@@ -166,7 +166,18 @@ public:
     MallocAllocator A;
     return Create(KeyStart, KeyEnd, A);
   }
-
+  
+  
+  /// GetStringMapEntryFromValue - Given a value that is known to be embedded
+  /// into a StringMapEntry, return the StringMapEntry itself.
+  static StringMapEntry &GetStringMapEntryFromValue(ValueTy &V) {
+    return *reinterpret_cast<StringMapEntry*>(reinterpret_cast<char*>(&V) -
+                                              sizeof(StringMapEntryBase));
+  }
+  static const StringMapEntry &GetStringMapEntryFromValue(const ValueTy &V) {
+    return GetStringMapEntryFromValue(const_cast<ValueTy&>(V));
+  }
+  
   /// Destroy - Destroy this StringMapEntry, releasing memory back to the
   /// specified allocator.
   template<typename AllocatorTy>