Skip to content

Commit 23d16da

Browse files
authored
Change a byte[] in KnownColorTable to be ReadOnlySpan<byte> (#51719)
1 parent 1e28943 commit 23d16da

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/libraries/Common/src/System/Drawing/KnownColorTable.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ internal static class KnownColorTable
238238
};
239239

240240
// All known color kinds (in order of definition in the KnownColor enum).
241-
public static readonly byte[] s_colorKindTable = new byte[]
241+
public static ReadOnlySpan<byte> ColorKindTable => new byte[]
242242
{
243243
// "not a known color"
244244
KnownColorKindUnknown,
@@ -466,11 +466,11 @@ internal static class KnownColorTable
466466
internal static Color ArgbToKnownColor(uint argb)
467467
{
468468
Debug.Assert((argb & Color.ARGBAlphaMask) == Color.ARGBAlphaMask);
469-
Debug.Assert(s_colorValueTable.Length == s_colorKindTable.Length);
469+
Debug.Assert(s_colorValueTable.Length == ColorKindTable.Length);
470470

471471
for (int index = 1; index < s_colorValueTable.Length; ++index)
472472
{
473-
if (s_colorKindTable[index] == KnownColorKindWeb && s_colorValueTable[index] == argb)
473+
if (ColorKindTable[index] == KnownColorKindWeb && s_colorValueTable[index] == argb)
474474
{
475475
return Color.FromKnownColor((KnownColor)index);
476476
}
@@ -484,7 +484,7 @@ public static uint KnownColorToArgb(KnownColor color)
484484
{
485485
Debug.Assert(color > 0 && color <= KnownColor.RebeccaPurple);
486486

487-
return s_colorKindTable[(int)color] == KnownColorKindSystem
487+
return ColorKindTable[(int)color] == KnownColorKindSystem
488488
? GetSystemColorArgb(color)
489489
: s_colorValueTable[(int)color];
490490
}

src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ private Color(long value, short state, string? name, KnownColor knownColor)
374374
public bool IsSystemColor => IsKnownColor && IsKnownColorSystem((KnownColor)knownColor);
375375

376376
internal static bool IsKnownColorSystem(KnownColor knownColor)
377-
=> KnownColorTable.s_colorKindTable[(int)knownColor] == KnownColorTable.KnownColorKindSystem;
377+
=> KnownColorTable.ColorKindTable[(int)knownColor] == KnownColorTable.KnownColorKindSystem;
378378

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

0 commit comments

Comments
 (0)