@@ -9,6 +9,7 @@ namespace Microsoft.AspNetCore.Razor;
9
9
10
10
internal static class EnumExtensions
11
11
{
12
+ // Note: This is written to allow the JIT to inline only the correct branch depending on the size of T.
12
13
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
13
14
public static unsafe void SetFlag < T > ( ref this T value , T flag )
14
15
where T : unmanaged, Enum
@@ -39,6 +40,7 @@ public static unsafe void SetFlag<T>(ref this T value, T flag)
39
40
Debug. Fail ( "Unexpected enum underlying type." ) ;
40
41
}
41
42
43
+ // Note: This is written to allow the JIT to inline only the correct branch depending on the size of T.
42
44
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
43
45
public static unsafe void ClearFlag< T > ( ref this T value , T flag )
44
46
where T : unmanaged , Enum
@@ -83,6 +85,8 @@ public static unsafe void UpdateFlag<T>(ref this T value, T flag, bool set)
83
85
}
84
86
}
85
87
88
+ // Note: This is written to allow the JIT to inline only the correct branch depending on the size of T.
89
+ // This is somewhat faster than Enum.HasFlag(...) when running on .NET Framework.
86
90
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
87
91
public static unsafe bool IsFlagSet< T> ( this T value , T flags )
88
92
where T : unmanaged , Enum
@@ -112,6 +116,7 @@ public static unsafe bool IsFlagSet<T>(this T value, T flags)
112
116
return false;
113
117
}
114
118
119
+ // Note: This is written to allow the JIT to inline only the correct branch depending on the size of T.
115
120
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
116
121
public static unsafe bool IsFlagClear< T > ( this T value , T flags )
117
122
where T : unmanaged, Enum
0 commit comments