From 45e39589411c8dfd625b71daba674b11286ea512 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 24 Jun 2008 21:58:29 +0000 Subject: 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 --- lib/VMCore/Constants.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/VMCore/Constants.cpp') 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(getOperand(i))->getZExtValue(); + Result[i] = (char)cast(getOperand(i))->getZExtValue(); return Result; } -- cgit v1.1