Add a fast path for setName("") on an unnamed value.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 19 Aug 2009 23:37:23 +0000 (23:37 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 19 Aug 2009 23:37:23 +0000 (23:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79492 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2c6ba0bc2321f4d5cecd4854ae87e243a5523079..88fde0a54ae6aebacd147ec588591bf7e003dd2c 100644 (file)
@@ -320,6 +320,16 @@ namespace llvm {
       return Twine(&Val, UHexKind, 0, EmptyKind);
     }
 
+    /// @}
+    /// @name Predicate Operations
+    /// @{
+
+    /// isTriviallyEmpty - Check if this twine is trivially empty; a false
+    /// return value does not necessarily mean the twine is empty.
+    bool isTriviallyEmpty() const {
+      return isNullary();
+    }
+
     /// @}
     /// @name String Operations
     /// @{
index 157245d9ea85e9732475dc3679ebeb6856b75238..34291b9d728fa7f7065d4ba0d6d4a1febbee9da9 100644 (file)
@@ -171,6 +171,10 @@ std::string Value::getNameStr() const {
 }
 
 void Value::setName(const Twine &NewName) {
+  // Fast path for common IRBuilder case of setName("") when there is no name.
+  if (NewName.isTriviallyEmpty() && !hasName())
+    return;
+
   SmallString<256> NameData;
   NewName.toVector(NameData);