add Value::getNameStart/getNameLen() accessors.
authorChris Lattner <sabre@nondot.org>
Fri, 10 Aug 2007 15:34:35 +0000 (15:34 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 10 Aug 2007 15:34:35 +0000 (15:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40989 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 44c4453b04a045577ec5181f8f692023c406f4d0..67af6edb8f98a6475636038f8125b0c5709372eb 100644 (file)
@@ -88,9 +88,23 @@ public:
 
   // All values can potentially be named...
   inline bool hasName() const { return Name != 0; }
+  ValueName *getValueName() const { return Name; }
+
+  /// getNameStart - Return a pointer to a null terminated string for this name.
+  /// Note that names can have null characters within the string as well as at
+  /// their end.  This always returns a non-null pointer.
+  const char *getNameStart() const;
+  
+  /// getNameLen - Return the length of the string, correctly handling nul
+  /// characters embedded into them.
+  unsigned getNameLen() const;
+
+  /// getName()/getNameStr() - Return the name of the specified value, 
+  /// *constructing a string* to hold it.  Because these are guaranteed to
+  /// construct a string, they are very expensive and should be avoided.
   std::string getName() const { return getNameStr(); }
   std::string getNameStr() const;
-  ValueName *getValueName() const { return Name; }
+
 
   void setName(const std::string &name);
   void setName(const char *Name, unsigned NameLen);
index 790ae17a9839dcb282a03e4be27454b0f322ab59..2178ce47a3f5ad7cf6761fc90be47075ea0748ef 100644 (file)
@@ -117,6 +117,21 @@ static bool getSymTab(Value *V, ValueSymbolTable *&ST) {
   return false;
 }
 
+/// getNameStart - Return a pointer to a null terminated string for this name.
+/// Note that names can have null characters within the string as well as at
+/// their end.  This always returns a non-null pointer.
+const char *Value::getNameStart() const {
+  if (Name == 0) return "";
+  return Name->getKeyData();
+}
+
+/// getNameLen - Return the length of the string, correctly handling nul
+/// characters embedded into them.
+unsigned Value::getNameLen() const {
+  return Name->getKeyLength();
+}
+
+
 std::string Value::getNameStr() const {
   if (Name == 0) return "";
   return std::string(Name->getKeyData(),