diff options
-rw-r--r-- | include/llvm/ADT/Twine.h | 10 | ||||
-rw-r--r-- | lib/VMCore/Value.cpp | 4 |
2 files changed, 14 insertions, 0 deletions
diff --git a/include/llvm/ADT/Twine.h b/include/llvm/ADT/Twine.h index 2c6ba0bc23..88fde0a54a 100644 --- a/include/llvm/ADT/Twine.h +++ b/include/llvm/ADT/Twine.h @@ -321,6 +321,16 @@ namespace llvm { } /// @} + /// @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 /// @{ diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 157245d9ea..34291b9d72 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -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); |