Add llvm::Value::getNameRef, for help in API migration.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 23 Jul 2009 18:50:53 +0000 (18:50 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 23 Jul 2009 18:50:53 +0000 (18:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76893 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Value.h
lib/VMCore/Value.cpp

index 40b1dab29574642d94215a763e4d2f01fb135efc..720cc1935b332fa2eecebc3cac1dca178a3ca53c 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "llvm/AbstractTypeUser.h"
 #include "llvm/Use.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include <iosfwd>
 #include <string>
@@ -129,7 +130,7 @@ public:
   /// construct a string, they are very expensive and should be avoided.
   std::string getName() const { return getNameStr(); }
   std::string getNameStr() const;
-
+  StringRef getNameRef() const;
 
   void setName(const std::string &name);
   void setName(const char *Name, unsigned NameLen);
index b3c0692c0e5c6c8304439aa4e8ba274b8f5f61a8..a78865224cdd21657a8fdb919318278358822769 100644 (file)
@@ -178,6 +178,11 @@ std::string Value::getNameStr() const {
                      Name->getKeyData()+Name->getKeyLength());
 }
 
+StringRef Value::getNameRef() const {
+  if (Name == 0) return StringRef();
+  return StringRef(Name->getKeyData(), Name->getKeyLength());
+}
+
 void Value::setName(const std::string &name) {
   setName(&name[0], name.size());
 }
@@ -238,7 +243,7 @@ void Value::setName(const char *NameStr, unsigned NameLen) {
   }
 
   // Name is changing to something new.
-  Name = ST->createValueName(NameStr, NameLen, this);
+  Name = ST->createValueName(StringRef(NameStr, NameLen), this);
 }