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

Experiment with Roslyn optimization for ROS<T> in assembly data section #60327

Merged
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
14 changes: 7 additions & 7 deletions src/libraries/Common/src/System/Drawing/KnownColorTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class KnownColorTable
public const byte KnownColorKindUnknown = 2;

// All known color values (in order of definition in the KnownColor enum).
public static readonly uint[] s_colorValueTable = new uint[]
public static ReadOnlySpan<uint> ColorValueTable => new uint[]
{
// "not a known color"
0,
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 == ColorKindTable.Length);
Debug.Assert(ColorValueTable.Length == ColorKindTable.Length);

for (int index = 1; index < s_colorValueTable.Length; ++index)
for (int index = 1; index < ColorValueTable.Length; ++index)
{
if (ColorKindTable[index] == KnownColorKindWeb && s_colorValueTable[index] == argb)
if (ColorKindTable[index] == KnownColorKindWeb && ColorValueTable[index] == argb)
{
return Color.FromKnownColor((KnownColor)index);
}
Expand All @@ -486,22 +486,22 @@ public static uint KnownColorToArgb(KnownColor color)

return ColorKindTable[(int)color] == KnownColorKindSystem
? GetSystemColorArgb(color)
: s_colorValueTable[(int)color];
: ColorValueTable[(int)color];
}

#if FEATURE_WINDOWS_SYSTEM_COLORS
public static uint GetSystemColorArgb(KnownColor color)
{
Debug.Assert(Color.IsKnownColorSystem(color));

return ColorTranslator.COLORREFToARGB(Interop.User32.GetSysColor((byte)s_colorValueTable[(int)color]));
return ColorTranslator.COLORREFToARGB(Interop.User32.GetSysColor((byte)ColorValueTable[(int)color]));
}
#else
public static uint GetSystemColorArgb(KnownColor color)
{
Debug.Assert(Color.IsKnownColorSystem(color));

return s_colorValueTable[(int)color];
return ColorValueTable[(int)color];
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static class Huffman
{
// HPack static huffman code. see: https://httpwg.org/specs/rfc7541.html#huffman.code
// Stored into two tables to optimize its initialization and memory consumption.
private static readonly uint[] s_encodingTableCodes = new uint[257]
private static ReadOnlySpan<uint> EncodingTableCodes => new uint[257]
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
{
0b11111111_11000000_00000000_00000000,
0b11111111_11111111_10110000_00000000,
Expand Down Expand Up @@ -537,7 +537,7 @@ internal static class Huffman

public static (uint encoded, int bitLength) Encode(int data)
{
return (s_encodingTableCodes[data], EncodingTableBitLengths[data]);
return (EncodingTableCodes[data], EncodingTableBitLengths[data]);
}

private static ushort[] GenerateDecodingLookupTree()
Expand Down Expand Up @@ -574,7 +574,7 @@ private static ushort[] GenerateDecodingLookupTree()
// it is guaranteed that for this huffman code generated decoding lookup tree MUST consist of exactly 15 lookup tables
var decodingTree = new ushort[15 * 256];

uint[] encodingTableCodes = s_encodingTableCodes;
ReadOnlySpan<uint> encodingTableCodes = EncodingTableCodes;
ReadOnlySpan<byte> encodingTableBitLengths = EncodingTableBitLengths;

int allocatedLookupTableIndex = 0;
Expand Down
32 changes: 16 additions & 16 deletions src/libraries/Common/src/System/Security/IdentityHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ namespace System.Security
/// </summary>
internal static class IdentityHelper
{
private static readonly char[] s_base32Char =
{
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5'
};

/// <summary>
/// Gives a hash equivalent to what Url.Normalize() gives.
/// </summary>
Expand Down Expand Up @@ -97,6 +89,14 @@ internal static string ToBase32StringSuitableForDirName(byte[] buff)
// Create l chars using the last 5 bits of each byte.
// Consume 3 MSB bits 5 bytes at a time.

ReadOnlySpan<char> base32Char = new char[]
{
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5'
};

do
{
byte b0 = (i < l) ? buff[i++] : (byte)0;
Expand All @@ -106,18 +106,18 @@ internal static string ToBase32StringSuitableForDirName(byte[] buff)
byte b4 = (i < l) ? buff[i++] : (byte)0;

// Consume the 5 Least significant bits of each byte
sb.Append(s_base32Char[b0 & 0x1F]);
sb.Append(s_base32Char[b1 & 0x1F]);
sb.Append(s_base32Char[b2 & 0x1F]);
sb.Append(s_base32Char[b3 & 0x1F]);
sb.Append(s_base32Char[b4 & 0x1F]);
sb.Append(base32Char[b0 & 0x1F]);
sb.Append(base32Char[b1 & 0x1F]);
sb.Append(base32Char[b2 & 0x1F]);
sb.Append(base32Char[b3 & 0x1F]);
sb.Append(base32Char[b4 & 0x1F]);

// Consume 3 MSB of b0, b1, MSB bits 6, 7 of b3, b4
sb.Append(s_base32Char[(
sb.Append(base32Char[(
((b0 & 0xE0) >> 5) |
((b3 & 0x60) >> 2))]);

sb.Append(s_base32Char[(
sb.Append(base32Char[(
((b1 & 0xE0) >> 5) |
((b4 & 0x60) >> 2))]);

Expand All @@ -132,7 +132,7 @@ internal static string ToBase32StringSuitableForDirName(byte[] buff)
if ((b4 & 0x80) != 0)
b2 |= 0x10;

sb.Append(s_base32Char[b2]);
sb.Append(base32Char[b2]);

} while (i < l);

Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Console/src/System/ConsolePal.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ private static void WriteSetColorString(bool foreground, ConsoleColor color)
int maxColors = TerminalFormatStrings.Instance.MaxColors; // often 8 or 16; 0 is invalid
if (maxColors > 0)
{
int ansiCode = _consoleColorToAnsiCode[ccValue] % maxColors;
int ansiCode = ConsoleColorToAnsiCode[ccValue] % maxColors;
evaluatedString = TermInfo.ParameterizedStrings.Evaluate(formatString, ansiCode);

WriteStdoutAnsiString(evaluatedString);
Expand Down Expand Up @@ -860,7 +860,7 @@ private static bool EmitAnsiColorCodes
/// corresponding ANSI values. We need to do the mapping manually.
/// See http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
/// </summary>
private static readonly int[] _consoleColorToAnsiCode = new int[]
private static ReadOnlySpan<byte> ConsoleColorToAnsiCode => new byte[]
{
// Dark/Normal colors
0, // Black,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,34 +121,32 @@ internal static bool IsRelational(int op)
/// Mapping from Operator to priorities
/// CONSIDER: fast, but hard to maintain
/// </summary>

private static readonly int[] s_priority = new int[] {
priStart, // Noop
priNeg, priNeg, priNot, // Unary -, +, Not
priBetweenAnd, priBetweenInLike, priBetweenInLike,
priRelOp, priRelOp, priRelOp, priRelOp, priRelOp, priRelOp,
priIs,
priBetweenInLike, // Like

priPlusMinus, priPlusMinus, // +, -
priMulDiv, priMulDiv, priIDiv, priMod, // *, /, \, Mod
priExp, // **

priAnd, priOr, priXor, priNot,
priAnd, priOr,

priParen, priProc, priDot, priDot, // Proc, Iff, Qula, Dot..

priMax, priMax, priMax, priMax, priMax, priMax, priMax,
priMax, priMax, priMax, priMax,
priMax,
};

internal static int Priority(int op)
{
if (op > s_priority.Length)
return priMax;
return s_priority[op];
ReadOnlySpan<int> priority = new int[]
{
priStart, // Noop
priNeg, priNeg, priNot, // Unary -, +, Not
priBetweenAnd, priBetweenInLike, priBetweenInLike,
priRelOp, priRelOp, priRelOp, priRelOp, priRelOp, priRelOp,
priIs,
priBetweenInLike, // Like

priPlusMinus, priPlusMinus, // +, -
priMulDiv, priMulDiv, priIDiv, priMod, // *, /, \, Mod
priExp, // **

priAnd, priOr, priXor, priNot,
priAnd, priOr,

priParen, priProc, priDot, priDot, // Proc, Iff, Qula, Dot..

priMax, priMax, priMax, priMax, priMax, priMax, priMax,
priMax, priMax, priMax, priMax,
priMax,
};

return (uint)op < priority.Length ? priority[op] : priMax;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ public struct SqlDateTime : INullable, IComparable, IXmlSerializable

private const int s_dayBase = 693595; // Jan 1 1900 is this many days from Jan 1 0001


private static readonly int[] s_daysToMonth365 = new int[] {
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
private static readonly int[] s_daysToMonth366 = new int[] {
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};

private static readonly DateTime s_minDateTime = new DateTime(1753, 1, 1);
private static readonly DateTime s_maxDateTime = DateTime.MaxValue;
private static readonly TimeSpan s_minTimeSpan = s_minDateTime.Subtract(s_SQLBaseDate);
Expand Down Expand Up @@ -105,7 +99,9 @@ public SqlDateTime(int year, int month, int day, int hour, int minute, int secon
{
if (year >= s_minYear && year <= s_maxYear && month >= 1 && month <= 12)
{
int[] days = IsLeapYear(year) ? s_daysToMonth366 : s_daysToMonth365;
ReadOnlySpan<int> days = IsLeapYear(year) ?
(ReadOnlySpan<int>)new int[] { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } :
(ReadOnlySpan<int>)new int[] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
if (day >= 1 && day <= days[month] - days[month - 1])
{
int y = year - 1;
Expand Down
Loading