|
3 | 3 |
|
4 | 4 | using System.Diagnostics; |
5 | 5 | using System.Runtime.CompilerServices; |
6 | | -using System.Runtime.InteropServices; |
7 | | - |
8 | | -#if NET |
9 | | -using System.Runtime.Intrinsics; |
10 | | -#endif |
11 | 6 |
|
12 | 7 | namespace System.Text.Encodings.Web |
13 | 8 | { |
14 | 9 | internal sealed partial class OptimizedInboxTextEncoder |
15 | 10 | { |
16 | | - /// <summary> |
17 | | - /// A bitmap which represents allowed ASCII code points. |
18 | | - /// </summary> |
19 | | - [StructLayout(LayoutKind.Explicit)] |
20 | | - private unsafe partial struct AllowedAsciiCodePoints |
21 | | - { |
22 | | - [FieldOffset(0)] // ensure same offset with AsVector field |
23 | | - private fixed byte AsBytes[16]; |
24 | | - |
25 | | -#if NET |
26 | | -#if !TARGET_BROWSER |
27 | | - [FieldOffset(0)] // ensure same offset with AsBytes field |
28 | | - internal Vector128<byte> AsVector; |
29 | | -#else |
30 | | - // This member shouldn't be accessed from browser-based code paths. |
31 | | - // All call sites should be trimmed away, which will also trim this member |
32 | | - // and the type hierarchy it links to. |
33 | | -#pragma warning disable CA1822 |
34 | | - internal Vector128<byte> AsVector => throw new PlatformNotSupportedException(); |
35 | | -#pragma warning restore CA1822 |
36 | | -#endif |
37 | | -#endif |
38 | | - |
39 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
40 | | - internal readonly bool IsAllowedAsciiCodePoint(uint codePoint) |
41 | | - { |
42 | | - if (codePoint > 0x7F) |
43 | | - { |
44 | | - return false; // non-ASCII |
45 | | - } |
46 | | - |
47 | | - uint mask = AsBytes[codePoint & 0xF]; |
48 | | - if ((mask & (0x1u << (int)(codePoint >> 4))) == 0) |
49 | | - { |
50 | | - return false; // ASCII but disallowed |
51 | | - } |
52 | | - |
53 | | - return true; |
54 | | - } |
55 | | - |
56 | | - internal void PopulateAllowedCodePoints(in AllowedBmpCodePointsBitmap allowedBmpCodePoints) |
57 | | - { |
58 | | - this = default; // clear all existing data |
59 | | - |
60 | | - // we only care about ASCII non-control chars; all control chars and non-ASCII chars are disallowed |
61 | | - for (int i = 0x20; i < 0x7F; i++) |
62 | | - { |
63 | | - if (allowedBmpCodePoints.IsCharAllowed((char)i)) |
64 | | - { |
65 | | - AsBytes[i & 0xF] |= (byte)(1 << (i >> 4)); |
66 | | - } |
67 | | - } |
68 | | - } |
69 | | - } |
70 | | - |
71 | 11 | /// <summary> |
72 | 12 | /// A bitmap which represents the 64-bit pre-escaped form of the ASCII code points. |
73 | 13 | /// A pre-escaped code point has the form [ WW 00 FF EE DD CC BB AA ], |
|
0 commit comments