From 93b617fac4be3ba167406c4eb48df3f72b9288f1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 24 Mar 2010 00:53:27 +0000 Subject: [PATCH] Add a method to get a StringMapEntry from a pointer to the string data it contains (similar to GetStringMapEntryFromValue). Patch by Greg Clayton! llvm-svn: 99371 --- include/llvm/ADT/StringMap.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h index 86e8546adca..482193859b6 100644 --- a/include/llvm/ADT/StringMap.h +++ b/include/llvm/ADT/StringMap.h @@ -216,6 +216,14 @@ public: static const StringMapEntry &GetStringMapEntryFromValue(const ValueTy &V) { return GetStringMapEntryFromValue(const_cast(V)); } + + /// GetStringMapEntryFromKeyData - Given key data that is known to be embedded + /// into a StringMapEntry, return the StringMapEntry itself. + static StringMapEntry &GetStringMapEntryFromKeyData(const char *KeyData) { + char *Ptr = const_cast(KeyData) - sizeof(StringMapEntry); + return *reinterpret_cast(Ptr); + } + /// Destroy - Destroy this StringMapEntry, releasing memory back to the /// specified allocator.