Simplify.
authorDaniel Dunbar <daniel@zuster.org>
Sun, 26 Jul 2009 00:42:33 +0000 (00:42 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 26 Jul 2009 00:42:33 +0000 (00:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77102 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Value.cpp

index 6157dd5a75326b391d6b3e90d35ae5e1d205e5aa..67cd11a3d194c70f205028952e70dcf07bab85d8 100644 (file)
@@ -177,7 +177,10 @@ void Value::setName(const Twine &NewName) {
   const char *NameStr = NameData.data();
   unsigned NameLen = NameData.size();
 
-  if (NameLen == 0 && !hasName()) return;
+  // Name isn't changing?
+  if (getName() == StringRef(NameStr, NameLen))
+    return;
+
   assert(getType() != Type::VoidTy && "Cannot assign a name to void values!");
   
   // Get the symbol table to update for this object.
@@ -193,13 +196,8 @@ void Value::setName(const Twine &NewName) {
       return;
     }
     
-    if (Name) {
-      // Name isn't changing?
-      if (NameLen == Name->getKeyLength() &&
-          !memcmp(Name->getKeyData(), NameStr, NameLen))
-        return;
+    if (Name)
       Name->Destroy();
-    }
     
     // NOTE: Could optimize for the case the name is shrinking to not deallocate
     // then reallocated.
@@ -213,11 +211,6 @@ void Value::setName(const Twine &NewName) {
   // NOTE: Could optimize for the case the name is shrinking to not deallocate
   // then reallocated.
   if (hasName()) {
-    // Name isn't changing?
-    if (NameLen == Name->getKeyLength() &&
-        !memcmp(Name->getKeyData(), NameStr, NameLen))
-      return;
-
     // Remove old name.
     ST->removeValueName(Name);
     Name->Destroy();