Skip to content

Commit 934fea8

Browse files
Add comments explaining the aggressive inlining behavior of EnumExtensions
1 parent b58f180 commit 934fea8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/EnumExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.AspNetCore.Razor;
99

1010
internal static class EnumExtensions
1111
{
12+
// Note: This is written to allow the JIT to inline only the correct branch depending on the size of T.
1213
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1314
public static unsafe void SetFlag<T>(ref this T value, T flag)
1415
where T : unmanaged, Enum
@@ -39,6 +40,7 @@ public static unsafe void SetFlag<T>(ref this T value, T flag)
3940
Debug.Fail("Unexpected enum underlying type.");
4041
}
4142

43+
// Note: This is written to allow the JIT to inline only the correct branch depending on the size of T.
4244
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4345
public static unsafe void ClearFlag<T>(ref this T value, T flag)
4446
where T : unmanaged, Enum
@@ -83,6 +85,8 @@ public static unsafe void UpdateFlag<T>(ref this T value, T flag, bool set)
8385
}
8486
}
8587

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.
8690
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8791
public static unsafe bool IsFlagSet<T>(this T value, T flags)
8892
where T : unmanaged, Enum
@@ -112,6 +116,7 @@ public static unsafe bool IsFlagSet<T>(this T value, T flags)
112116
return false;
113117
}
114118

119+
// Note: This is written to allow the JIT to inline only the correct branch depending on the size of T.
115120
[MethodImpl(MethodImplOptions.AggressiveInlining)]
116121
public static unsafe bool IsFlagClear<T>(this T value, T flags)
117122
where T : unmanaged, Enum

0 commit comments

Comments
 (0)