[llvm-commits] [llvm] r77105 - in /llvm/trunk: include/llvm/Value.h lib/VMCore/Value.cpp

Daniel Dunbar daniel at zuster.org
Sat Jul 25 17:51:56 PDT 2009


Author: ddunbar
Date: Sat Jul 25 19:51:56 2009
New Revision: 77105

URL: http://llvm.org/viewvc/llvm-project?rev=77105&view=rev
Log:
Rewrite getName{Start,End,Len} in terms of getName(), instead of vice-versa.

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

Modified: llvm/trunk/include/llvm/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Value.h?rev=77105&r1=77104&r2=77105&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Value.h (original)
+++ llvm/trunk/include/llvm/Value.h Sat Jul 25 19:51:56 2009
@@ -114,18 +114,22 @@
   /// 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;
+  const char *getNameStart() const { return getName().begin(); }
   /// getNameEnd - Return a pointer to the end of the name.
-  const char *getNameEnd() const { return getNameStart() + getNameLen(); }
+  const char *getNameEnd() const { return getName().end(); }
   
   /// getNameLen - Return the length of the string, correctly handling nul
   /// characters embedded into them.
-  unsigned getNameLen() const;
+  unsigned getNameLen() const { return getName().size(); }
 
-  /// 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.
-  StringRef getName() const { return StringRef(getNameStart(), getNameLen()); }
+  /// getName() - Return a constant reference to the value's name. This is cheap
+  /// and guaranteed to return the same reference as long as the value is not
+  /// modified.
+  StringRef getName() const;
+
+  /// getNameStr() - Return the name of the specified value, *constructing a
+  /// string* to hold it.  This is guaranteed to construct a string and is very
+  /// expensive, clients should use getName() unless necessary.
   std::string getNameStr() const;
 
   /// setName() - Change the name of the value, choosing a new unique name if

Modified: llvm/trunk/lib/VMCore/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Value.cpp?rev=77105&r1=77104&r2=77105&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Value.cpp (original)
+++ llvm/trunk/lib/VMCore/Value.cpp Sat Jul 25 19:51:56 2009
@@ -151,21 +151,11 @@
   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();
+StringRef Value::getName() const {
+  if (!Name) return StringRef();
+  return Name->getKey();
 }
 
-/// getNameLen - Return the length of the string, correctly handling nul
-/// characters embedded into them.
-unsigned Value::getNameLen() const {
-  return Name ? Name->getKeyLength() : 0;
-}
-
-
 std::string Value::getNameStr() const {
   return getName().str();
 }





More information about the llvm-commits mailing list