diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 5d7c35f232d..de61c37d6e3 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -191,7 +191,8 @@ ConstantFP::ConstantFP(const Type *Ty, double V) : Constant(Ty) { ConstantArray::ConstantArray(const ArrayType *T, const std::vector &V) : Constant(T) { - for (unsigned i = 0; i < V.size(); i++) { + Operands.reserve(V.size()); + for (unsigned i = 0, e = V.size(); i != e; ++i) { assert(V[i]->getType() == T->getElementType()); Operands.push_back(Use(V[i], this)); } @@ -202,7 +203,8 @@ ConstantStruct::ConstantStruct(const StructType *T, const StructType::ElementTypes &ETypes = T->getElementTypes(); assert(V.size() == ETypes.size() && "Invalid initializer vector for constant structure"); - for (unsigned i = 0; i < V.size(); i++) { + Operands.reserve(V.size()); + for (unsigned i = 0, e = V.size(); i != e; ++i) { assert(V[i]->getType() == ETypes[i]); Operands.push_back(Use(V[i], this)); }