[llvm-commits] [llvm] r74133 - in /llvm/trunk: include/llvm/Constants.h lib/VMCore/Constants.cpp
Devang Patel
dpatel at apple.com
Wed Jun 24 15:43:05 PDT 2009
Author: dpatel
Date: Wed Jun 24 17:42:39 2009
New Revision: 74133
URL: http://llvm.org/viewvc/llvm-project?rev=74133&view=rev
Log:
Add constructor to create MDString using std::string
Modified:
llvm/trunk/include/llvm/Constants.h
llvm/trunk/lib/VMCore/Constants.cpp
Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=74133&r1=74132&r2=74133&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Wed Jun 24 17:42:39 2009
@@ -865,6 +865,7 @@
/// 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.
///
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=74133&r1=74132&r2=74133&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Wed Jun 24 17:42:39 2009
@@ -1803,6 +1803,17 @@
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));
More information about the llvm-commits
mailing list