Cache the sizes of vectors instead of calculating them all over the place.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149954 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2012-02-07 01:48:12 +00:00
parent a7a3f04eb9
commit c5de7fea7b

View File

@ -391,10 +391,11 @@ FunctionType::FunctionType(Type *Result, ArrayRef<Type*> Params,
FunctionType *FunctionType::get(Type *ReturnType, FunctionType *FunctionType::get(Type *ReturnType,
ArrayRef<Type*> Params, bool isVarArg) { ArrayRef<Type*> Params, bool isVarArg) {
// TODO: This is brutally slow. // TODO: This is brutally slow.
unsigned ParamsSize = Params.size();
std::vector<Type*> Key; std::vector<Type*> Key;
Key.reserve(Params.size()+2); Key.reserve(ParamsSize + 2);
Key.push_back(const_cast<Type*>(ReturnType)); Key.push_back(const_cast<Type*>(ReturnType));
for (unsigned i = 0, e = Params.size(); i != e; ++i) for (unsigned i = 0, e = ParamsSize; i != e; ++i)
Key.push_back(const_cast<Type*>(Params[i])); Key.push_back(const_cast<Type*>(Params[i]));
if (isVarArg) if (isVarArg)
Key.push_back(0); Key.push_back(0);
@ -404,7 +405,7 @@ FunctionType *FunctionType::get(Type *ReturnType,
if (FT == 0) { if (FT == 0) {
FT = (FunctionType*) pImpl->TypeAllocator. FT = (FunctionType*) pImpl->TypeAllocator.
Allocate(sizeof(FunctionType) + sizeof(Type*)*(Params.size()+1), Allocate(sizeof(FunctionType) + sizeof(Type*) * (ParamsSize + 1),
AlignOf<FunctionType>::Alignment); AlignOf<FunctionType>::Alignment);
new (FT) FunctionType(ReturnType, Params, isVarArg); new (FT) FunctionType(ReturnType, Params, isVarArg);
} }
@ -467,12 +468,12 @@ void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
if (isPacked) if (isPacked)
setSubclassData(getSubclassData() | SCDB_Packed); setSubclassData(getSubclassData() | SCDB_Packed);
Type **Elts = getContext().pImpl-> unsigned NumElements = Elements.size();
TypeAllocator.Allocate<Type*>(Elements.size()); Type **Elts = getContext().pImpl->TypeAllocator.Allocate<Type*>(NumElements);
memcpy(Elts, Elements.data(), sizeof(Elements[0])*Elements.size()); memcpy(Elts, Elements.data(), sizeof(Elements[0]) * NumElements);
ContainedTys = Elts; ContainedTys = Elts;
NumContainedTys = Elements.size(); NumContainedTys = NumElements;
} }
void StructType::setName(StringRef Name) { void StructType::setName(StringRef Name) {
@ -497,9 +498,10 @@ void StructType::setName(StringRef Name) {
SmallString<64> TempStr(Name); SmallString<64> TempStr(Name);
TempStr.push_back('.'); TempStr.push_back('.');
raw_svector_ostream TmpStream(TempStr); raw_svector_ostream TmpStream(TempStr);
unsigned NameSize = Name.size();
do { do {
TempStr.resize(Name.size()+1); TempStr.resize(NameSize + 1);
TmpStream.resync(); TmpStream.resync();
TmpStream << getContext().pImpl->NamedStructTypesUniqueID++; TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;