@@ -2020,36 +2020,16 @@ static void lookupConcreteNestedType(NominalTypeDecl *decl,
2020
2020
concreteDecls.push_back (cast<TypeDecl>(member));
2021
2021
}
2022
2022
2023
- static auto findBestConcreteNestedType (SmallVectorImpl<TypeDecl *> &concreteDecls) {
2024
- return std::min_element (concreteDecls.begin (), concreteDecls.end (),
2025
- [](TypeDecl *type1, TypeDecl *type2) {
2026
- return TypeDecl::compare (type1, type2) < 0 ;
2027
- });
2023
+ static TypeDecl * findBestConcreteNestedType (SmallVectorImpl<TypeDecl *> &concreteDecls) {
2024
+ return * std::min_element (concreteDecls.begin (), concreteDecls.end (),
2025
+ [](TypeDecl *type1, TypeDecl *type2) {
2026
+ return TypeDecl::compare (type1, type2) < 0 ;
2027
+ });
2028
2028
}
2029
2029
2030
2030
TypeDecl *EquivalenceClass::lookupNestedType (
2031
2031
GenericSignatureBuilder &builder,
2032
- Identifier name,
2033
- SmallVectorImpl<TypeDecl *> *otherConcreteTypes) {
2034
- // Populates the result structures from the given cache entry.
2035
- auto populateResult = [&](const CachedNestedType &cache) -> TypeDecl * {
2036
- if (otherConcreteTypes)
2037
- otherConcreteTypes->clear ();
2038
-
2039
- // If there aren't any types in the cache, we're done.
2040
- if (cache.types .empty ()) return nullptr ;
2041
-
2042
- // The first type in the cache is always the final result.
2043
- // Collect the rest in the concrete-declarations list, if needed.
2044
- if (otherConcreteTypes) {
2045
- for (auto type : ArrayRef<TypeDecl *>(cache.types ).slice (1 )) {
2046
- otherConcreteTypes->push_back (type);
2047
- }
2048
- }
2049
-
2050
- return cache.types .front ();
2051
- };
2052
-
2032
+ Identifier name) {
2053
2033
// If we have a cached value that is up-to-date, use that.
2054
2034
auto cached = nestedTypeNameCache.find (name);
2055
2035
if (cached != nestedTypeNameCache.end () &&
@@ -2059,7 +2039,7 @@ TypeDecl *EquivalenceClass::lookupNestedType(
2059
2039
(!concreteType ||
2060
2040
cached->second .concreteTypePresent == concreteType->getCanonicalType ())) {
2061
2041
++NumNestedTypeCacheHits;
2062
- return populateResult ( cached->second ) ;
2042
+ return cached->second . type ;
2063
2043
}
2064
2044
2065
2045
// Cache miss; go compute the result.
@@ -2112,24 +2092,16 @@ TypeDecl *EquivalenceClass::lookupNestedType(
2112
2092
entry.concreteTypePresent =
2113
2093
concreteType ? concreteType->getCanonicalType () : CanType ();
2114
2094
if (bestAssocType) {
2115
- entry.types .push_back (bestAssocType);
2116
- entry.types .insert (entry.types .end (),
2117
- concreteDecls.begin (), concreteDecls.end ());
2095
+ entry.type = bestAssocType;
2118
2096
assert (bestAssocType->getOverriddenDecls ().empty () &&
2119
2097
" Lookup should never keep a non-anchor associated type" );
2120
2098
} else if (!concreteDecls.empty ()) {
2121
2099
// Find the best concrete type.
2122
- auto bestConcreteTypeIter = findBestConcreteNestedType (concreteDecls);
2123
-
2124
- // Put the best concrete type first; the rest will follow.
2125
- entry.types .push_back (*bestConcreteTypeIter);
2126
- entry.types .insert (entry.types .end (),
2127
- concreteDecls.begin (), bestConcreteTypeIter);
2128
- entry.types .insert (entry.types .end (),
2129
- bestConcreteTypeIter + 1 , concreteDecls.end ());
2100
+ entry.type = findBestConcreteNestedType (concreteDecls);
2130
2101
}
2131
2102
2132
- return populateResult ((nestedTypeNameCache[name] = std::move (entry)));
2103
+ nestedTypeNameCache[name] = entry;
2104
+ return entry.type ;
2133
2105
}
2134
2106
2135
2107
static Type getSugaredDependentType (Type type,
@@ -3829,8 +3801,7 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
3829
3801
if (concreteDecls.empty ())
3830
3802
return ResolvedType::forUnresolved (nullptr );
3831
3803
3832
- auto bestConcreteTypeIter = findBestConcreteNestedType (concreteDecls);
3833
- concreteDecl = *bestConcreteTypeIter;
3804
+ concreteDecl = findBestConcreteNestedType (concreteDecls);
3834
3805
}
3835
3806
}
3836
3807
0 commit comments