[llvm-commits] [llvm] r42480 - /llvm/trunk/include/llvm/ADT/StringMap.h

Chris Lattner sabre at nondot.org
Sun Sep 30 01:31:46 PDT 2007


Author: lattner
Date: Sun Sep 30 03:31:46 2007
New Revision: 42480

URL: http://llvm.org/viewvc/llvm-project?rev=42480&view=rev
Log:
Add a helper useful when mapping from a map element to its hash node.

Modified:
    llvm/trunk/include/llvm/ADT/StringMap.h

Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=42480&r1=42479&r2=42480&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Sun Sep 30 03:31:46 2007
@@ -166,7 +166,18 @@
     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>





More information about the llvm-commits mailing list