Index: lib/IR/Type.cpp =================================================================== --- lib/IR/Type.cpp +++ lib/IR/Type.cpp @@ -297,20 +297,18 @@ FunctionType *FunctionType::get(Type *ReturnType, ArrayRef Params, bool isVarArg) { LLVMContextImpl *pImpl = ReturnType->getContext().pImpl; - FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg); - auto I = pImpl->FunctionTypes.find_as(Key); + const FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg); FunctionType *FT; - - if (I == pImpl->FunctionTypes.end()) { + auto Insertion = pImpl->FunctionTypes.insert_as(nullptr, Key); + if (Insertion.second) { FT = (FunctionType *)pImpl->TypeAllocator.Allocate( sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1), alignof(FunctionType)); new (FT) FunctionType(ReturnType, Params, isVarArg); - pImpl->FunctionTypes.insert(FT); + *Insertion.first = FT; } else { - FT = *I; + FT = *Insertion.first; } - return FT; }