forked from OSchip/llvm-project
Reduce code duplication.
This also moves strlen out of the mutex scope. llvm-svn: 106545
This commit is contained in:
parent
53a61dc531
commit
eb9165c08f
|
@ -73,15 +73,7 @@ public:
|
||||||
GetConstCString (const char *cstr)
|
GetConstCString (const char *cstr)
|
||||||
{
|
{
|
||||||
if (cstr)
|
if (cstr)
|
||||||
{
|
return GetConstCStringWithLength (cstr, strlen (cstr));
|
||||||
Mutex::Locker locker (m_mutex);
|
|
||||||
llvm::StringRef string_ref (cstr);
|
|
||||||
llvm::StringMapEntry<uint32_t>& entry = m_string_map.GetOrCreateValue (string_ref);
|
|
||||||
const char *ccstr = entry.getKeyData();
|
|
||||||
llvm::StringMapEntry<uint32_t>&reconstituted_entry = GetStringMapEntryFromKeyData (ccstr);
|
|
||||||
assert (&entry == &reconstituted_entry);
|
|
||||||
return ccstr;
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,14 +98,8 @@ public:
|
||||||
{
|
{
|
||||||
if (cstr)
|
if (cstr)
|
||||||
{
|
{
|
||||||
Mutex::Locker locker (m_mutex);
|
int trimmed_len = std::min<int> (strlen (cstr), cstr_len);
|
||||||
int actual_cstr_len = strlen (cstr);
|
return GetConstCStringWithLength (cstr, trimmed_len);
|
||||||
llvm::StringRef string_ref (cstr, std::min<int>(actual_cstr_len, cstr_len));
|
|
||||||
llvm::StringMapEntry<uint32_t>& entry = m_string_map.GetOrCreateValue (string_ref);
|
|
||||||
const char *ccstr = entry.getKeyData();
|
|
||||||
llvm::StringMapEntry<uint32_t>&reconstituted_entry = GetStringMapEntryFromKeyData (ccstr);
|
|
||||||
assert (&entry == &reconstituted_entry);
|
|
||||||
return ccstr;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue