diff options
-rw-r--r-- | llvm/include/llvm/Value.h | 3 | ||||
-rw-r--r-- | llvm/lib/VMCore/Value.cpp | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/llvm/include/llvm/Value.h b/llvm/include/llvm/Value.h index 40b1dab2957..720cc1935b3 100644 --- a/llvm/include/llvm/Value.h +++ b/llvm/include/llvm/Value.h @@ -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); diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp index b3c0692c0e5..a78865224cd 100644 --- a/llvm/lib/VMCore/Value.cpp +++ b/llvm/lib/VMCore/Value.cpp @@ -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); } |