1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5//
6// Hash table associated with each module that records for all types defined in that module the mapping
7// between type name and token (or TypeHandle).
8//
9
10
11#ifndef CLASSHASH_INL
12#define CLASSHASH_INL
13
14// Low bit is discriminator between unresolved and resolved.
15// Low bit == 0: Resolved: data == TypeHandle
16// Low bit == 1: Unresolved: data encodes either a typeDef or exportTypeDef. Use bit 31 as discriminator.
17//
18// If not resolved, bit 31 (64-bit: yes, it's bit31, not the high bit!) is discriminator between regular typeDef and exportedType
19//
20// Bit31 == 0: mdTypeDef: 000t tttt tttt tttt tttt tttt tttt ttt1
21// Bit31 == 1: mdExportedType: 100e eeee eeee eeee eeee eeee eeee eee1
22//
23//
24
25/* static */
26inline PTR_VOID EEClassHashTable::CompressClassDef(mdToken cl)
27{
28 LIMITED_METHOD_CONTRACT;
29
30 _ASSERTE(TypeFromToken(cl) == mdtTypeDef || TypeFromToken(cl) == mdtExportedType);
31
32 switch (TypeFromToken(cl))
33 {
34 case mdtTypeDef: return (PTR_VOID)( 0 | (((ULONG_PTR)cl & 0x00ffffff) << 1) | EECLASSHASH_TYPEHANDLE_DISCR);
35 case mdtExportedType: return (PTR_VOID)(EECLASSHASH_MDEXPORT_DISCR | (((ULONG_PTR)cl & 0x00ffffff) << 1) | EECLASSHASH_TYPEHANDLE_DISCR);
36 default:
37 _ASSERTE(!"Can't get here.");
38 return 0;
39 }
40}
41
42inline DWORD EEClassHashTable::Hash(LPCUTF8 pszNamespace, LPCUTF8 pszClassName)
43{
44 CONTRACTL
45 {
46 NOTHROW;
47 GC_NOTRIGGER;
48 MODE_ANY;
49 FORBID_FAULT;
50 SUPPORTS_DAC;
51 }
52 CONTRACTL_END;
53
54
55 DWORD dwHash = 5381;
56 DWORD dwChar;
57
58 while ((dwChar = *pszNamespace++) != 0)
59 dwHash = ((dwHash << 5) + dwHash) ^ dwChar;
60
61 while ((dwChar = *pszClassName++) != 0)
62 dwHash = ((dwHash << 5) + dwHash) ^ dwChar;
63
64 return dwHash;
65}
66
67#endif // CLASSHASH_INL
68