| | | 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 | | |
| | | 4 | | using System.Runtime.CompilerServices; |
| | | 5 | | |
| | | 6 | | namespace System.Reflection.Metadata.Ecma335 |
| | | 7 | | { |
| | | 8 | | internal static class TypeDefOrRefTag |
| | | 9 | | { |
| | | 10 | | internal const int NumberOfBits = 2; |
| | | 11 | | internal const int LargeRowSize = 0x00000001 << (16 - NumberOfBits); |
| | | 12 | | internal const uint TypeDef = 0x00000000; |
| | | 13 | | internal const uint TypeRef = 0x00000001; |
| | | 14 | | internal const uint TypeSpec = 0x00000002; |
| | | 15 | | internal const uint TagMask = 0x00000003; |
| | | 16 | | internal const uint TagToTokenTypeByteVector = TokenTypeIds.TypeDef >> 24 | TokenTypeIds.TypeRef >> 16 | TokenTy |
| | | 17 | | internal const TableMask TablesReferenced = |
| | | 18 | | TableMask.TypeDef |
| | | 19 | | | TableMask.TypeRef |
| | | 20 | | | TableMask.TypeSpec; |
| | | 21 | | |
| | | 22 | | // inlining improves perf of the tight loop in FindSystemObjectTypeDef by 25% |
| | | 23 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 24 | | internal static EntityHandle ConvertToHandle(uint typeDefOrRefTag) |
| | 0 | 25 | | { |
| | 0 | 26 | | uint tokenType = (TagToTokenTypeByteVector >> ((int)(typeDefOrRefTag & TagMask) << 3)) << TokenTypeIds.RowId |
| | 0 | 27 | | uint rowId = (typeDefOrRefTag >> NumberOfBits); |
| | | 28 | | |
| | 0 | 29 | | if (tokenType == 0 || (rowId & ~TokenTypeIds.RIDMask) != 0) |
| | 0 | 30 | | { |
| | 0 | 31 | | Throw.InvalidCodedIndex(); |
| | | 32 | | } |
| | | 33 | | |
| | 0 | 34 | | return new EntityHandle(tokenType | rowId); |
| | 0 | 35 | | } |
| | | 36 | | } |
| | | 37 | | } |
| | | 38 | | |