[llvm-commits] [llvm] r93249 - in /llvm/trunk: include/llvm/Metadata.h lib/VMCore/Metadata.cpp

Devang Patel dpatel at apple.com
Tue Jan 12 10:57:57 PST 2010


Author: dpatel
Date: Tue Jan 12 12:57:56 2010
New Revision: 93249

URL: http://llvm.org/viewvc/llvm-project?rev=93249&view=rev
Log:
Use Twine, instead of StringRef, for consistency.

Modified:
    llvm/trunk/include/llvm/Metadata.h
    llvm/trunk/lib/VMCore/Metadata.cpp

Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=93249&r1=93248&r2=93249&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Tue Jan 12 12:57:56 2010
@@ -194,10 +194,10 @@
 
   void setParent(Module *M) { Parent = M; }
 protected:
-  explicit NamedMDNode(LLVMContext &C, StringRef N, MDNode*const *Vals, 
+  explicit NamedMDNode(LLVMContext &C, const Twine &N, MDNode*const *Vals, 
                        unsigned NumVals, Module *M = 0);
 public:
-  static NamedMDNode *Create(LLVMContext &C, StringRef N,
+  static NamedMDNode *Create(LLVMContext &C, const Twine &N,
                              MDNode *const *MDs, 
                              unsigned NumMDs, Module *M = 0) {
     return new NamedMDNode(C, N, MDs, NumMDs, M);
@@ -229,7 +229,7 @@
   void addOperand(MDNode *M);
 
   /// setName - Set the name of this named metadata.
-  void setName(StringRef Name);
+  void setName(const Twine &NewName);
 
   /// getName - Return a constant reference to this named metadata's name.
   StringRef getName() const;

Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=93249&r1=93248&r2=93249&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Jan 12 12:57:56 2010
@@ -18,6 +18,7 @@
 #include "llvm/Instruction.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/SmallString.h"
 #include "SymbolTableListTraitsImpl.h"
 #include "llvm/Support/ValueHandle.h"
 using namespace llvm;
@@ -263,7 +264,7 @@
   return *(SmallVector<WeakVH, 4>*)Operands;
 }
 
-NamedMDNode::NamedMDNode(LLVMContext &C, StringRef N,
+NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
                          MDNode *const *MDs,
                          unsigned NumMDs, Module *ParentModule)
   : Value(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
@@ -322,11 +323,23 @@
 }
 
 /// setName - Set the name of this named metadata.
-void NamedMDNode::setName(StringRef N) {
-  assert (!N.empty() && "Invalid named metadata name!");
-  Name = N.str();
+void NamedMDNode::setName(const Twine &NewName) {
+  assert (!NewName.isTriviallyEmpty() && "Invalid named metadata name!");
+
+  SmallString<256> NameData;
+  NewName.toVector(NameData);
+
+  const char *NameStr = NameData.data();
+  unsigned NameLen = NameData.size();
+
+  StringRef NameRef = StringRef(NameStr, NameLen);
+  // Name isn't changing?
+  if (getName() == NameRef)
+    return;
+
+  Name = NameRef.str();
   if (Parent)
-    Parent->getMDSymbolTable().insert(N, this);
+    Parent->getMDSymbolTable().insert(NameRef, this);
 }
 
 /// getName - Return a constant reference to this named metadata's name.





More information about the llvm-commits mailing list