From 5149932068f535e1ff13b91c9669f55718c60a07 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 19 Aug 2009 23:37:23 +0000 Subject: [PATCH] Add a fast path for setName("") on an unnamed value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79492 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/Twine.h | 10 ++++++++++ lib/VMCore/Value.cpp | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/include/llvm/ADT/Twine.h b/include/llvm/ADT/Twine.h index 2c6ba0bc232..88fde0a54ae 100644 --- a/include/llvm/ADT/Twine.h +++ b/include/llvm/ADT/Twine.h @@ -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 /// @{ diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 157245d9ea8..34291b9d728 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);