[cfe-commits] r149936 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp
Bill Wendling
isanbard at gmail.com
Mon Feb 6 16:13:27 PST 2012
Author: void
Date: Mon Feb 6 18:13:27 2012
New Revision: 149936
URL: http://llvm.org/viewvc/llvm-project?rev=149936&view=rev
Log:
Use a more efficient container for these values. Also reserve space when using a
std::vector.
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=149936&r1=149935&r2=149936&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Mon Feb 6 18:13:27 2012
@@ -590,8 +590,8 @@
// Build a struct with the union sub-element as the first member,
// and padded to the appropriate size
- std::vector<llvm::Constant*> Elts;
- std::vector<llvm::Type*> Types;
+ SmallVector<llvm::Constant*, 2> Elts;
+ SmallVector<llvm::Type*, 2> Types;
Elts.push_back(C);
Types.push_back(C->getType());
unsigned CurSize = CGM.getTargetData().getTypeAllocSize(C->getType());
@@ -689,7 +689,6 @@
isa<ObjCEncodeExpr>(ILE->getInit(0))))
return Visit(ILE->getInit(0));
- std::vector<llvm::Constant*> Elts;
llvm::ArrayType *AType =
cast<llvm::ArrayType>(ConvertType(ILE->getType()));
llvm::Type *ElemTy = AType->getElementType();
@@ -700,6 +699,8 @@
unsigned NumInitableElts = std::min(NumInitElements, NumElements);
// Copy initializer elements.
+ std::vector<llvm::Constant*> Elts;
+ Elts.reserve(NumInitableElts + NumElements);
unsigned i = 0;
bool RewriteType = false;
for (; i < NumInitableElts; ++i) {
@@ -727,6 +728,7 @@
if (RewriteType) {
// FIXME: Try to avoid packing the array
std::vector<llvm::Type*> 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 @@
if (!CommonElementType) {
// FIXME: Try to avoid packing the array
std::vector<llvm::Type*> 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);
More information about the cfe-commits
mailing list