In ConstantArray::getAsString(), we know the size of the resultant string in advance...
authorOwen Anderson <resistor@mac.com>
Tue, 24 Jun 2008 21:58:29 +0000 (21:58 +0000)
committerOwen Anderson <resistor@mac.com>
Tue, 24 Jun 2008 21:58:29 +0000 (21:58 +0000)
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

index e6398a3bbd3b5c9dd243f5e9c0ab5e94b718e3f3..39c0a8c70107f5c551f574db91eee3e6449cef88 100644 (file)
@@ -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;
 }