diff options
author | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
---|---|---|
committer | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
commit | ef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch) | |
tree | dee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/vm/classhash.inl | |
download | coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2 coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip |
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/vm/classhash.inl')
-rw-r--r-- | src/vm/classhash.inl | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/vm/classhash.inl b/src/vm/classhash.inl new file mode 100644 index 0000000000..a5658c72eb --- /dev/null +++ b/src/vm/classhash.inl @@ -0,0 +1,68 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +// +// Hash table associated with each module that records for all types defined in that module the mapping +// between type name and token (or TypeHandle). +// + + +#ifndef CLASSHASH_INL +#define CLASSHASH_INL + +// Low bit is discriminator between unresolved and resolved. +// Low bit == 0: Resolved: data == TypeHandle +// Low bit == 1: Unresolved: data encodes either a typeDef or exportTypeDef. Use bit 31 as discriminator. +// +// If not resolved, bit 31 (64-bit: yes, it's bit31, not the high bit!) is discriminator between regular typeDef and exportedType +// +// Bit31 == 0: mdTypeDef: 000t tttt tttt tttt tttt tttt tttt ttt1 +// Bit31 == 1: mdExportedType: 100e eeee eeee eeee eeee eeee eeee eee1 +// +// + +/* static */ +inline PTR_VOID EEClassHashTable::CompressClassDef(mdToken cl) +{ + LIMITED_METHOD_CONTRACT; + + _ASSERTE(TypeFromToken(cl) == mdtTypeDef || TypeFromToken(cl) == mdtExportedType); + + switch (TypeFromToken(cl)) + { + case mdtTypeDef: return (PTR_VOID)( 0 | (((ULONG_PTR)cl & 0x00ffffff) << 1) | EECLASSHASH_TYPEHANDLE_DISCR); + case mdtExportedType: return (PTR_VOID)(EECLASSHASH_MDEXPORT_DISCR | (((ULONG_PTR)cl & 0x00ffffff) << 1) | EECLASSHASH_TYPEHANDLE_DISCR); + default: + _ASSERTE(!"Can't get here."); + return 0; + } +} + +inline DWORD EEClassHashTable::Hash(LPCUTF8 pszNamespace, LPCUTF8 pszClassName) +{ + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + MODE_ANY; + FORBID_FAULT; + SUPPORTS_DAC; + } + CONTRACTL_END; + + + DWORD dwHash = 5381; + DWORD dwChar; + + while ((dwChar = *pszNamespace++) != 0) + dwHash = ((dwHash << 5) + dwHash) ^ dwChar; + + while ((dwChar = *pszClassName++) != 0) + dwHash = ((dwHash << 5) + dwHash) ^ dwChar; + + return dwHash; +} + +#endif // CLASSHASH_INL |