From e6c42dd6d3cc1e0a8a11224a11bcfbd8c60c6fff Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 23 Jul 2009 18:50:53 +0000 Subject: [PATCH] Add llvm::Value::getNameRef, for help in API migration. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76893 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Value.h | 3 ++- lib/VMCore/Value.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 40b1dab2957..720cc1935b3 100644 --- a/include/llvm/Value.h +++ b/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 #include @@ -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/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index b3c0692c0e5..a78865224cd 100644 --- a/lib/VMCore/Value.cpp +++ b/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); } -- 2.11.0