[llvm-commits] [llvm] r52690 - /llvm/trunk/lib/VMCore/Constants.cpp
Owen Anderson
resistor at mac.com
Tue Jun 24 14:58:29 PDT 2008
Author: resistor
Date: Tue Jun 24 16:58:29 2008
New Revision: 52690
URL: http://llvm.org/viewvc/llvm-project?rev=52690&view=rev
Log:
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.
Modified:
llvm/trunk/lib/VMCore/Constants.cpp
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=52690&r1=52689&r2=52690&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Tue Jun 24 16:58:29 2008
@@ -1378,8 +1378,9 @@
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;
}
More information about the llvm-commits
mailing list