@@ -141,10 +141,10 @@ DWORD EETypeHashTable::GetCount()
141141 return BaseGetElementCount ();
142142}
143143
144- static DWORD HashTypeHandle (DWORD level, TypeHandle t);
144+ static DWORD HashTypeHandle (TypeHandle t);
145145
146146// Calculate hash value for a type def or instantiated type def
147- static DWORD HashPossiblyInstantiatedType (DWORD level, mdTypeDef token, Instantiation inst)
147+ static DWORD HashPossiblyInstantiatedType (mdTypeDef token, Instantiation inst)
148148{
149149 CONTRACTL
150150 {
@@ -161,25 +161,18 @@ static DWORD HashPossiblyInstantiatedType(DWORD level, mdTypeDef token, Instanti
161161 dwHash = ((dwHash << 5 ) + dwHash) ^ token;
162162 if (!inst.IsEmpty ())
163163 {
164- dwHash = ((dwHash << 5 ) + dwHash) ^ inst.GetNumArgs ();
165-
166- // Hash two levels of the hiearchy. A simple nesting of generics instantiations is
167- // pretty common in generic collections, e.g.: ICollection<KeyValuePair<TKey, TValue>>
168- if (level < 2 )
164+ // Hash n type parameters
165+ for (DWORD i = 0 ; i < inst.GetNumArgs (); i++)
169166 {
170- // Hash n type parameters
171- for (DWORD i = 0 ; i < inst.GetNumArgs (); i++)
172- {
173- dwHash = ((dwHash << 5 ) + dwHash) ^ HashTypeHandle (level+1 , inst[i]);
174- }
167+ dwHash = ((dwHash << 5 ) + dwHash) ^ inst[i].AsTAddr ();
175168 }
176169 }
177170
178171 return dwHash;
179172}
180173
181174// Calculate hash value for a function pointer type
182- static DWORD HashFnPtrType (DWORD level, BYTE callConv, DWORD numArgs, TypeHandle *retAndArgTypes)
175+ static DWORD HashFnPtrType (BYTE callConv, DWORD numArgs, TypeHandle *retAndArgTypes)
183176{
184177 WRAPPER_NO_CONTRACT;
185178 SUPPORTS_DAC;
@@ -188,31 +181,29 @@ static DWORD HashFnPtrType(DWORD level, BYTE callConv, DWORD numArgs, TypeHandle
188181 dwHash = ((dwHash << 5 ) + dwHash) ^ ELEMENT_TYPE_FNPTR;
189182 dwHash = ((dwHash << 5 ) + dwHash) ^ callConv;
190183 dwHash = ((dwHash << 5 ) + dwHash) ^ numArgs;
191- if (level < 1 )
184+
185+ for (DWORD i = 0 ; i <= numArgs; i++)
192186 {
193- for (DWORD i = 0 ; i <= numArgs; i++)
194- {
195- dwHash = ((dwHash << 5 ) + dwHash) ^ HashTypeHandle (level+1 , retAndArgTypes[i]);
196- }
187+ dwHash = ((dwHash << 5 ) + dwHash) ^ retAndArgTypes[i].AsTAddr ();
197188 }
198189
199190 return dwHash;
200191}
201192
202193// Calculate hash value for an array/pointer/byref type
203- static DWORD HashParamType (DWORD level, CorElementType kind, TypeHandle typeParam)
194+ static DWORD HashParamType (CorElementType kind, TypeHandle typeParam)
204195{
205196 WRAPPER_NO_CONTRACT;
206197 INT_PTR dwHash = 5381 ;
207198
208199 dwHash = ((dwHash << 5 ) + dwHash) ^ kind;
209- dwHash = ((dwHash << 5 ) + dwHash) ^ HashTypeHandle (level, typeParam);
200+ dwHash = ((dwHash << 5 ) + dwHash) ^ typeParam. AsTAddr ( );
210201
211202 return dwHash;
212203}
213204
214205// Calculate hash value from type handle
215- static DWORD HashTypeHandle (DWORD level, TypeHandle t)
206+ static DWORD HashTypeHandle (TypeHandle t)
216207{
217208 CONTRACTL
218209 {
@@ -229,29 +220,30 @@ static DWORD HashTypeHandle(DWORD level, TypeHandle t)
229220
230221 if (t.HasTypeParam ())
231222 {
232- retVal = HashParamType (level, t.GetInternalCorElementType (), t.GetTypeParam ());
233- }
234- else if (t.IsGenericVariable ())
235- {
236- retVal = (dac_cast<PTR_TypeVarTypeDesc>(t.AsTypeDesc ())->GetToken ());
223+ retVal = HashParamType (t.GetInternalCorElementType (), t.GetTypeParam ());
237224 }
238225 else if (t.HasInstantiation ())
239226 {
240- retVal = HashPossiblyInstantiatedType (level, t.GetCl (), t.GetInstantiation ());
227+ retVal = HashPossiblyInstantiatedType (t.GetCl (), t.GetInstantiation ());
241228 }
242229 else if (t.IsFnPtrType ())
243230 {
244231 FnPtrTypeDesc* pTD = t.AsFnPtrType ();
245- retVal = HashFnPtrType (level, pTD->GetCallConv (), pTD->GetNumArgs (), pTD->GetRetAndArgTypesPointer ());
232+ retVal = HashFnPtrType (pTD->GetCallConv (), pTD->GetNumArgs (), pTD->GetRetAndArgTypesPointer ());
233+ }
234+ else if (t.IsGenericVariable ())
235+ {
236+ _ASSERTE (!" Generic variables are unexpected here." );
237+ retVal = t.AsTAddr ();
246238 }
247239 else
248- retVal = HashPossiblyInstantiatedType (level, t.GetCl (), Instantiation ());
240+ retVal = HashPossiblyInstantiatedType (t.GetCl (), Instantiation ());
249241
250242 return retVal;
251243}
252244
253245// Calculate hash value from key
254- static DWORD HashTypeKey (TypeKey* pKey)
246+ DWORD HashTypeKey (TypeKey* pKey)
255247{
256248 CONTRACTL
257249 {
@@ -265,15 +257,15 @@ static DWORD HashTypeKey(TypeKey* pKey)
265257
266258 if (pKey->GetKind () == ELEMENT_TYPE_CLASS)
267259 {
268- return HashPossiblyInstantiatedType (0 , pKey->GetTypeToken (), pKey->GetInstantiation ());
260+ return HashPossiblyInstantiatedType (pKey->GetTypeToken (), pKey->GetInstantiation ());
269261 }
270262 else if (pKey->GetKind () == ELEMENT_TYPE_FNPTR)
271263 {
272- return HashFnPtrType (0 , pKey->GetCallConv (), pKey->GetNumArgs (), pKey->GetRetAndArgTypes ());
264+ return HashFnPtrType (pKey->GetCallConv (), pKey->GetNumArgs (), pKey->GetRetAndArgTypes ());
273265 }
274266 else
275267 {
276- return HashParamType (0 , pKey->GetKind (), pKey->GetElementType ());
268+ return HashParamType (pKey->GetKind (), pKey->GetElementType ());
277269 }
278270}
279271
@@ -552,7 +544,7 @@ VOID EETypeHashTable::InsertValue(TypeHandle data)
552544
553545 pNewEntry->SetTypeHandle (data);
554546
555- BaseInsertEntry (HashTypeHandle (0 , data), pNewEntry);
547+ BaseInsertEntry (HashTypeHandle (data), pNewEntry);
556548}
557549
558550#endif // #ifndef DACCESS_COMPILE
0 commit comments