From: Owen Anderson Date: Tue, 24 Jun 2008 21:58:29 +0000 (+0000) Subject: In ConstantArray::getAsString(), we know the size of the resultant string in advance... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=45e39589411c8dfd625b71daba674b11286ea512;p=oota-llvm.git 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 --- diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index e6398a3bbd3..39c0a8c7010 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; }