mirror of
https://github.com/intel/llvm.git
synced 2026-01-15 12:25:46 +08:00
I modified the StringMap that was being used to unique our debugger C strings
to have the value for the map be a "const char *" instead of an unused uint32_t. This allows us to store the uniqued mangled/demangled counterpart in this map for mangled names. This also speeds up the mangled/demangled counterpart lookup that used to be maintained in a STL map by having direct access to the data. If we eventually need to associate other strings to strings to more data, we can make the value of the StringMap have a more complex value. Added the start of a history source and history event class. It isn't being used by anything yet, but might be shortly. llvm-svn: 132813
This commit is contained in:
@@ -32,6 +32,10 @@ using namespace lldb_private;
|
||||
class Pool
|
||||
{
|
||||
public:
|
||||
typedef const char * StringPoolValueType;
|
||||
typedef llvm::StringMap<StringPoolValueType, llvm::BumpPtrAllocator> StringPool;
|
||||
typedef llvm::StringMapEntry<StringPoolValueType> StringPoolEntryType;
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Default constructor
|
||||
//
|
||||
@@ -51,24 +55,44 @@ public:
|
||||
}
|
||||
|
||||
|
||||
static llvm::StringMapEntry<uint32_t> &
|
||||
static StringPoolEntryType &
|
||||
GetStringMapEntryFromKeyData (const char *keyData)
|
||||
{
|
||||
char *ptr = const_cast<char*>(keyData) - sizeof (llvm::StringMapEntry<uint32_t>);
|
||||
return *reinterpret_cast<llvm::StringMapEntry<uint32_t>*>(ptr);
|
||||
char *ptr = const_cast<char*>(keyData) - sizeof (StringPoolEntryType);
|
||||
return *reinterpret_cast<StringPoolEntryType*>(ptr);
|
||||
}
|
||||
|
||||
size_t
|
||||
GetConstCStringLength (const char *ccstr)
|
||||
GetConstCStringLength (const char *ccstr) const
|
||||
{
|
||||
if (ccstr)
|
||||
{
|
||||
llvm::StringMapEntry<uint32_t>&entry = GetStringMapEntryFromKeyData (ccstr);
|
||||
const StringPoolEntryType&entry = GetStringMapEntryFromKeyData (ccstr);
|
||||
return entry.getKey().size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
StringPoolValueType
|
||||
GetMangledCounterpart (const char *ccstr) const
|
||||
{
|
||||
if (ccstr)
|
||||
return GetStringMapEntryFromKeyData (ccstr).getValue();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
SetMangledCounterparts (const char *key_ccstr, const char *value_ccstr)
|
||||
{
|
||||
if (key_ccstr && value_ccstr)
|
||||
{
|
||||
GetStringMapEntryFromKeyData (key_ccstr).setValue(value_ccstr);
|
||||
GetStringMapEntryFromKeyData (value_ccstr).setValue(key_ccstr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *
|
||||
GetConstCString (const char *cstr)
|
||||
{
|
||||
@@ -84,12 +108,32 @@ public:
|
||||
{
|
||||
Mutex::Locker locker (m_mutex);
|
||||
llvm::StringRef string_ref (cstr, cstr_len);
|
||||
llvm::StringMapEntry<uint32_t>& entry = m_string_map.GetOrCreateValue (string_ref);
|
||||
StringPoolEntryType& entry = m_string_map.GetOrCreateValue (string_ref);
|
||||
return entry.getKeyData();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
GetConstCStringAndSetMangledCounterPart (const char *demangled_cstr, const char *mangled_ccstr)
|
||||
{
|
||||
if (demangled_cstr)
|
||||
{
|
||||
Mutex::Locker locker (m_mutex);
|
||||
// Make string pool entry with the mangled counterpart already set
|
||||
StringPoolEntryType& entry = m_string_map.GetOrCreateValue (llvm::StringRef (demangled_cstr), mangled_ccstr);
|
||||
|
||||
// Extract the const version of the demangled_cstr
|
||||
const char *demangled_ccstr = entry.getKeyData();
|
||||
// Now assign the demangled const string as the counterpart of the
|
||||
// mangled const string...
|
||||
GetStringMapEntryFromKeyData (mangled_ccstr).setValue(demangled_ccstr);
|
||||
// Return the constant demangled C string
|
||||
return demangled_ccstr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
GetConstTrimmedCStringWithLength (const char *cstr, int cstr_len)
|
||||
{
|
||||
@@ -114,7 +158,7 @@ public:
|
||||
const_iterator end = m_string_map.end();
|
||||
for (const_iterator pos = m_string_map.begin(); pos != end; ++pos)
|
||||
{
|
||||
mem_size += sizeof(llvm::StringMapEntry<uint32_t>) + pos->getKey().size();
|
||||
mem_size += sizeof(StringPoolEntryType) + pos->getKey().size();
|
||||
}
|
||||
return mem_size;
|
||||
}
|
||||
@@ -123,7 +167,6 @@ protected:
|
||||
//------------------------------------------------------------------
|
||||
// Typedefs
|
||||
//------------------------------------------------------------------
|
||||
typedef llvm::StringMap<uint32_t, llvm::BumpPtrAllocator> StringPool;
|
||||
typedef StringPool::iterator iterator;
|
||||
typedef StringPool::const_iterator const_iterator;
|
||||
|
||||
@@ -320,6 +363,19 @@ ConstString::SetCString (const char *cstr)
|
||||
m_string = StringPool().GetConstCString (cstr);
|
||||
}
|
||||
|
||||
void
|
||||
ConstString::SetCStringWithMangledCounterpart (const char *demangled, const ConstString &mangled)
|
||||
{
|
||||
m_string = StringPool().GetConstCStringAndSetMangledCounterPart (demangled, mangled.m_string);
|
||||
}
|
||||
|
||||
bool
|
||||
ConstString::GetMangledCounterpart (ConstString &counterpart) const
|
||||
{
|
||||
counterpart.m_string = StringPool().GetMangledCounterpart(m_string);
|
||||
return counterpart;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Set the string value in the object by uniquing "cstr_len" bytes
|
||||
// starting at the "cstr" string value in our global string pool.
|
||||
|
||||
Reference in New Issue
Block a user