From a7a3f04eb9a18c11940ab1486709c63c8bd296ff Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 7 Feb 2012 01:27:51 +0000 Subject: [PATCH] Reserve space in these vectors to prevent having to grow the array too much. This gets us an addition 0.9% on 445.gobmk. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149952 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Constants.cpp | 7 ++++--- lib/VMCore/Type.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index a2f3b3f0b32..6dbc1449f24 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -784,9 +784,10 @@ Constant *ConstantArray::get(ArrayType *Ty, ArrayRef V) { StructType *ConstantStruct::getTypeForElements(LLVMContext &Context, ArrayRef V, bool Packed) { - SmallVector EltTypes; - for (unsigned i = 0, e = V.size(); i != e; ++i) - EltTypes.push_back(V[i]->getType()); + unsigned VecSize = V.size(); + SmallVector EltTypes(VecSize); + for (unsigned i = 0; i != VecSize; ++i) + EltTypes[i] = V[i]->getType(); return StructType::get(Context, EltTypes, Packed); } diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index f5c88ccd38a..14a5aae70f8 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -440,11 +440,12 @@ bool FunctionType::isValidArgumentType(Type *ArgTy) { StructType *StructType::get(LLVMContext &Context, ArrayRef ETypes, bool isPacked) { // FIXME: std::vector is horribly inefficient for this probe. - std::vector Key; - for (unsigned i = 0, e = ETypes.size(); i != e; ++i) { + unsigned ETypesSize = ETypes.size(); + std::vector Key(ETypesSize); + for (unsigned i = 0, e = ETypesSize; i != e; ++i) { assert(isValidElementType(ETypes[i]) && "Invalid type for structure element!"); - Key.push_back(ETypes[i]); + Key[i] = ETypes[i]; } if (isPacked) Key.push_back(0); -- 2.11.0