From 9972958a898bf57dcaf4b9285c62854dbcecc4b8 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 7 Feb 2012 00:13:27 +0000 Subject: Use a more efficient container for these values. Also reserve space when using a std::vector. llvm-svn: 149936 --- clang/lib/CodeGen/CGExprConstant.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index ee0d9a4a81f..c68225b5ece 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -590,8 +590,8 @@ public: // Build a struct with the union sub-element as the first member, // and padded to the appropriate size - std::vector Elts; - std::vector Types; + SmallVector Elts; + SmallVector Types; Elts.push_back(C); Types.push_back(C->getType()); unsigned CurSize = CGM.getTargetData().getTypeAllocSize(C->getType()); @@ -689,7 +689,6 @@ public: isa(ILE->getInit(0)))) return Visit(ILE->getInit(0)); - std::vector Elts; llvm::ArrayType *AType = cast(ConvertType(ILE->getType())); llvm::Type *ElemTy = AType->getElementType(); @@ -700,6 +699,8 @@ public: unsigned NumInitableElts = std::min(NumInitElements, NumElements); // Copy initializer elements. + std::vector Elts; + Elts.reserve(NumInitableElts + NumElements); unsigned i = 0; bool RewriteType = false; for (; i < NumInitableElts; ++i) { @@ -727,6 +728,7 @@ public: if (RewriteType) { // FIXME: Try to avoid packing the array std::vector Types; + Types.reserve(NumInitableElts + NumElements); for (unsigned i = 0, e = Elts.size(); i < e; ++i) Types.push_back(Elts[i]->getType()); llvm::StructType *SType = llvm::StructType::get(AType->getContext(), @@ -1132,6 +1134,7 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value, if (!CommonElementType) { // FIXME: Try to avoid packing the array std::vector Types; + Types.reserve(NumElements); for (unsigned i = 0, e = Elts.size(); i < e; ++i) Types.push_back(Elts[i]->getType()); llvm::StructType *SType = llvm::StructType::get(VMContext, Types, true); -- cgit v1.2.3