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
This commit is contained in:
Owen Anderson 2008-06-24 21:58:29 +00:00
parent 873e1b5642
commit 45e3958941

View 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;
}