aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2008-06-24 21:58:29 +0000
committerOwen Anderson <resistor@mac.com>2008-06-24 21:58:29 +0000
commit45e39589411c8dfd625b71daba674b11286ea512 (patch)
tree554d3e6aac79e72d1ff76791579c90a2fb3b0035 /lib/VMCore/Constants.cpp
parent873e1b56427eee7879168b50cca8a85b04f18093 (diff)
downloadexternal_llvm-45e39589411c8dfd625b71daba674b11286ea512.zip
external_llvm-45e39589411c8dfd625b71daba674b11286ea512.tar.gz
external_llvm-45e39589411c8dfd625b71daba674b11286ea512.tar.bz2
In ConstantArray::getAsString(), we know the size of the resultant string in advance so we can pre-allocate it and just fill in
the entries. This improves the time for the AsmPrinter on InstructionCombining.cpp from 0.4248s to 0.3370s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52690 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r--lib/VMCore/Constants.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index e6398a3..39c0a8c 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1378,8 +1378,9 @@ bool ConstantArray::isCString() const {
std::string ConstantArray::getAsString() const {
assert(isString() && "Not a string!");
std::string Result;
+ Result.reserve(getNumOperands());
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- Result += (char)cast<ConstantInt>(getOperand(i))->getZExtValue();
+ Result[i] = (char)cast<ConstantInt>(getOperand(i))->getZExtValue();
return Result;
}