Fix bug: Assembler/2002-10-08-LargeArrayPerformance.ll by using
authorChris Lattner <sabre@nondot.org>
Tue, 8 Oct 2002 23:33:52 +0000 (23:33 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 8 Oct 2002 23:33:52 +0000 (23:33 +0000)
std::vector::reserve when possible

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4085 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Constants.cpp

index 5d7c35f232d0efd87df8c518875df1df3bd23452..de61c37d6e32b4cb0e888677d83b9fe8d14c58eb 100644 (file)
@@ -191,7 +191,8 @@ ConstantFP::ConstantFP(const Type *Ty, double V) : Constant(Ty) {
 
 ConstantArray::ConstantArray(const ArrayType *T,
                              const std::vector<Constant*> &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));
   }