Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change a byte[] in KnownColorTable to be ReadOnlySpan<byte> #51719

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libraries/Common/src/System/Drawing/KnownColorTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ internal static class KnownColorTable
};

// All known color kinds (in order of definition in the KnownColor enum).
public static readonly byte[] s_colorKindTable = new byte[]
public static ReadOnlySpan<byte> ColorKindTable => new byte[]
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
{
// "not a known color"
KnownColorKindUnknown,
Expand Down Expand Up @@ -466,11 +466,11 @@ internal static class KnownColorTable
internal static Color ArgbToKnownColor(uint argb)
{
Debug.Assert((argb & Color.ARGBAlphaMask) == Color.ARGBAlphaMask);
Debug.Assert(s_colorValueTable.Length == s_colorKindTable.Length);
Debug.Assert(s_colorValueTable.Length == ColorKindTable.Length);

for (int index = 1; index < s_colorValueTable.Length; ++index)
{
if (s_colorKindTable[index] == KnownColorKindWeb && s_colorValueTable[index] == argb)
if (ColorKindTable[index] == KnownColorKindWeb && s_colorValueTable[index] == argb)
{
return Color.FromKnownColor((KnownColor)index);
}
Expand All @@ -484,7 +484,7 @@ public static uint KnownColorToArgb(KnownColor color)
{
Debug.Assert(color > 0 && color <= KnownColor.RebeccaPurple);

return s_colorKindTable[(int)color] == KnownColorKindSystem
return ColorKindTable[(int)color] == KnownColorKindSystem
? GetSystemColorArgb(color)
: s_colorValueTable[(int)color];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private Color(long value, short state, string? name, KnownColor knownColor)
public bool IsSystemColor => IsKnownColor && IsKnownColorSystem((KnownColor)knownColor);

internal static bool IsKnownColorSystem(KnownColor knownColor)
=> KnownColorTable.s_colorKindTable[(int)knownColor] == KnownColorTable.KnownColorKindSystem;
=> KnownColorTable.ColorKindTable[(int)knownColor] == KnownColorTable.KnownColorKindSystem;

// Used for the [DebuggerDisplay]. Inlining in the attribute is possible, but
// against best practices as the current project language parses the string with
Expand Down