1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Add constructor to create MDString using std::string

llvm-svn: 74133
This commit is contained in:
Devang Patel 2009-06-24 22:42:39 +00:00
parent 9832095b30
commit 715a8c1154
2 changed files with 12 additions and 0 deletions

View File

@ -865,6 +865,7 @@ public:
/// get() - Static factory methods - Return objects of the specified value.
///
static MDString *get(const char *StrBegin, const char *StrEnd);
static MDString *get(const std::string &Str);
/// size() - The length of this string.
///

View File

@ -1803,6 +1803,17 @@ MDString *MDString::get(const char *StrBegin, const char *StrEnd) {
return S;
}
MDString *MDString::get(const std::string &Str) {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(
Str.data(), Str.data() + Str.size());
MDString *&S = Entry.getValue();
if (!S) S = new MDString(Entry.getKeyData(),
Entry.getKeyData() + Entry.getKeyLength());
return S;
}
void MDString::destroyConstant() {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd));