Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ static MILGuidData()

internal static readonly Guid GUID_ContainerFormatWmp = new Guid(0x57a37caa, 0x367a, 0x4540, 0x91, 0x6b, 0xf1, 0x83, 0xc5, 0x09, 0x3a, 0x4b);

internal static readonly byte[] GUID_VendorMicrosoft = new byte[] { 0xca, 0x49, 0xe7, 0xf0, 0xef, 0xed, 0x89, 0x45, 0xa7, 0x3a, 0xee, 0xe, 0x62, 0x6a, 0x2a, 0x2b };
internal static ReadOnlySpan<byte> GUID_VendorMicrosoft => [0xca, 0x49, 0xe7, 0xf0, 0xef, 0xed, 0x89, 0x45, 0xa7, 0x3a, 0xee, 0xe, 0x62, 0x6a, 0x2a, 0x2b];
}
#endregion // Guids
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ private static void ReplaceImplicitImports(XmlDocument xmlProjectDoc)
XmlNode previousNodeImportProps = null;
XmlNode previousNodeImportTargets = null;

foreach (string sdk in sdks.Split(_semicolonChar).Select(i => i.Trim()))
foreach (string sdk in sdks.Split(s_semicolonChar).Select(i => i.Trim()))
{
// <Project Sdk="Microsoft.NET.Sdk">
// <Project Sdk="My.Custom.Sdk/1.0.0">
Expand Down Expand Up @@ -952,7 +952,7 @@ static XmlNode CreateImportProjectSdkNode(XmlDocument xmlProjectDoc, string proj

private const string WPFTMP = "wpftmp";

private static readonly char[] _semicolonChar = new char[] { ';' };
private static readonly char[] s_semicolonChar = [';'];

#endregion Private Fields

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ private LZCodec LZCodec
internal const byte DefaultBAACount = 8;
internal const byte MaxBAACount = 10;

private static ReadOnlySpan<double> DefaultFirstSquareRoot => [1, 1, 1, 4, 9, 16, 36, 49];

private static readonly double[] DefaultFirstSquareRoot = { 1, 1, 1, 4, 9, 16, 36, 49};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,13 @@ private void ExamineStreamHeader(Stream inkdata, out bool fBase64, out bool fGif
return;
}

private static readonly byte[] Base64HeaderBytes
= new byte[]{(byte)'b',
(byte)'a',
(byte)'s',
(byte)'e',
(byte)'6',
(byte)'4',
(byte)':'};
private static ReadOnlySpan<byte> Base64HeaderBytes => [(byte)'b',
(byte)'a',
(byte)'s',
(byte)'e',
(byte)'6',
(byte)'4',
(byte)':'];

#if OLD_ISF
/// <summary>
Expand Down Expand Up @@ -2113,15 +2112,14 @@ private bool IsBase64Data(Stream data)
long currentPosition = data.Position;
try
{
byte[] isfBase64PrefixBytes = Base64HeaderBytes;
if (data.Length < isfBase64PrefixBytes.Length)
if (data.Length < Base64HeaderBytes.Length)
{
return false;
}

for (int x = 0; x < isfBase64PrefixBytes.Length; x++)
for (int x = 0; x < Base64HeaderBytes.Length; x++)
{
if ((byte)data.ReadByte() != isfBase64PrefixBytes[x])
if ((byte)data.ReadByte() != Base64HeaderBytes[x])
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,14 @@ internal struct ValueRecordTable
const ushort XAdvanceDeviceFlag = 0x0040;
const ushort YAdvanceDeviceFlag = 0x0080;

private static ushort[] BitCount =
new ushort[16] { 0, 2, 2, 4, 2, 4, 4, 6, 2, 4, 4, 6, 4, 6, 6, 8 };
private static ReadOnlySpan<ushort> BitCount => [0, 2, 2, 4,
2, 4, 4, 6,
2, 4, 4, 6,
4, 6, 6, 8];

public static ushort Size(ushort Format)
{
return (ushort)(BitCount[Format&0x000F]+BitCount[(Format>>4)&0x000F]);
return (ushort)(BitCount[Format & 0x000F] + BitCount[(Format >> 4) & 0x000F]);
}

public void AdjustPos( FontTable Table,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private bool IsValidCursorType(CursorType cursorType)

private SafeHandle _cursorHandle;

private static readonly int[] CursorTypes = {
private static ReadOnlySpan<int> CursorTypes => [
0, // None
NativeMethods.IDC_NO,
NativeMethods.IDC_ARROW,
Expand Down Expand Up @@ -383,6 +383,6 @@ private bool IsValidCursorType(CursorType cursorType)
NativeMethods.IDC_ARROW + 149, // ScrollSWCursor
NativeMethods.IDC_ARROW + 150, // ScrollSECursor
NativeMethods.IDC_ARROW + 151 // ArrowCDCursor
};
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ internal static Rect GetBoundsHelper(Pen pen, Matrix worldMatrix, Point center,
{
unsafe
{
Point * pPoints = stackalloc Point[(int)c_pointCount];
Point* pPoints = stackalloc Point[(int)c_pointCount];
EllipseGeometry.GetPointList(pPoints, c_pointCount, center, radiusX, radiusY);

fixed (byte *pTypes = EllipseGeometry.s_roundedPathTypes)
fixed (byte* pTypes = RoundedPathTypes) //Merely retrieves the pointer to static PE data, no actual pinning occurs
{
rect = Geometry.GetBoundsHelper(
pen,
Expand All @@ -206,10 +206,10 @@ internal override bool ContainsInternal(Pen pen, Point hitPoint, double toleranc
{
unsafe
{
Point *pPoints = stackalloc Point[(int)GetPointCount()];
Point* pPoints = stackalloc Point[(int)GetPointCount()];
EllipseGeometry.GetPointList(pPoints, GetPointCount(), Center, RadiusX, RadiusY);

fixed (byte* pTypes = GetTypeList())
fixed (byte* pTypes = RoundedPathTypes) //Merely retrieves the pointer to static PE data, no actual pinning occurs
{
return ContainsInternal(
pen,
Expand Down Expand Up @@ -383,9 +383,8 @@ private unsafe static void GetPointList(Point * points, uint pointsCount, Point
points[8].Y = points[9].Y = points[10].Y = center.Y - radiusY;
}

private byte[] GetTypeList() { return s_roundedPathTypes; }
private uint GetPointCount() { return c_pointCount; }
private uint GetSegmentCount() { return c_segmentCount; }
private static uint GetPointCount() { return c_pointCount; }
private static uint GetSegmentCount() { return c_segmentCount; }

#region Static Data

Expand All @@ -396,18 +395,16 @@ private unsafe static void GetPointList(Point * points, uint pointsCount, Point
private const UInt32 c_pointCount = 13;

private const byte c_smoothBezier = (byte)MILCoreSegFlags.SegTypeBezier |
(byte)MILCoreSegFlags.SegIsCurved |
(byte)MILCoreSegFlags.SegSmoothJoin;

private static readonly byte[] s_roundedPathTypes = {
(byte)MILCoreSegFlags.SegTypeBezier |
(byte)MILCoreSegFlags.SegIsCurved |
(byte)MILCoreSegFlags.SegSmoothJoin |
(byte)MILCoreSegFlags.SegClosed,
c_smoothBezier,
c_smoothBezier,
c_smoothBezier
};
(byte)MILCoreSegFlags.SegIsCurved |
(byte)MILCoreSegFlags.SegSmoothJoin;

private static ReadOnlySpan<byte> RoundedPathTypes => [(byte)MILCoreSegFlags.SegTypeBezier |
(byte)MILCoreSegFlags.SegIsCurved |
(byte)MILCoreSegFlags.SegSmoothJoin |
(byte)MILCoreSegFlags.SegClosed,
c_smoothBezier,
c_smoothBezier,
c_smoothBezier];

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal static Rect GetBoundsHelper(Pen pen, Matrix worldMatrix, Point pt1, Poi
pPoints[0] = pt1;
pPoints[1] = pt2;

fixed (byte *pTypes = LineGeometry.s_lineTypes)
fixed (byte* pTypes = LineTypes) //Merely retrieves the pointer to static PE data, no actual pinning occurs
{
return Geometry.GetBoundsHelper(
pen,
Expand All @@ -140,11 +140,11 @@ internal override bool ContainsInternal(Pen pen, Point hitPoint, double toleranc
{
unsafe
{
Point *pPoints = stackalloc Point[2];
Point* pPoints = stackalloc Point[2];
pPoints[0] = StartPoint;
pPoints[1] = EndPoint;

fixed (byte* pTypes = GetTypeList())
fixed (byte* pTypes = LineTypes) //Merely retrieves the pointer to static PE data, no actual pinning occurs
{
return ContainsInternal(
pen,
Expand Down Expand Up @@ -185,13 +185,11 @@ public override double GetArea(double tolerance, ToleranceType type)
return 0.0;
}

private byte[] GetTypeList() { return s_lineTypes; }
private static ReadOnlySpan<byte> LineTypes => [(byte)MILCoreSegFlags.SegTypeLine];

private static byte[] s_lineTypes = new byte[] { (byte)MILCoreSegFlags.SegTypeLine };
private static uint GetPointCount() { return c_pointCount; }

private uint GetPointCount() { return c_pointCount; }

private uint GetSegmentCount() { return c_segmentCount; }
private static uint GetSegmentCount() { return c_segmentCount; }

/// <summary>
/// GetAsPathGeometry - return a PathGeometry version of this Geometry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ internal static Rect GetBoundsHelper(Pen pen, Matrix worldMatrix, Rect rect, dou
// We've checked that rect isn't empty above
Invariant.Assert(pointCount != 0);

Point * pPoints = stackalloc Point[(int)pointCount];
Point* pPoints = stackalloc Point[(int)pointCount];
RectangleGeometry.GetPointList(pPoints, pointCount, rect, radiusX, radiusY);

fixed (byte *pTypes = RectangleGeometry.GetTypeList(rect, radiusX, radiusY))
fixed (byte* pTypes = GetTypeList(rect, radiusX, radiusY)) //Merely retrieves the pointer to static PE data, no actual pinning occurs
{
boundingRect = Geometry.GetBoundsHelper(
pen,
Expand Down Expand Up @@ -259,10 +259,10 @@ internal override bool ContainsInternal(Pen pen, Point hitPoint, double toleranc

unsafe
{
Point *pPoints = stackalloc Point[(int)pointCount];
Point* pPoints = stackalloc Point[(int)pointCount];
RectangleGeometry.GetPointList(pPoints, pointCount, rect, radiusX, radiusY);

fixed (byte* pTypes = GetTypeList(rect, radiusX, radiusY))
fixed (byte* pTypes = GetTypeList(rect, radiusX, radiusY)) //Merely retrieves the pointer to static PE data, no actual pinning occurs
{
return ContainsInternal(
pen,
Expand Down Expand Up @@ -510,19 +510,19 @@ private unsafe static void GetPointList(Point * points, uint pointsCount, Rect r
}
}

private static byte[] GetTypeList(Rect rect, double radiusX, double radiusY)
private static ReadOnlySpan<byte> GetTypeList(Rect rect, double radiusX, double radiusY)
{
if (rect.IsEmpty)
{
return null;
}
else if (IsRounded(radiusX, radiusY))
{
return s_roundedPathTypes;
return RoundedPathTypes;
}
else
{
return s_squaredPathTypes;
return SquaredPathTypes;
}
}

Expand Down Expand Up @@ -610,30 +610,28 @@ public override bool MayHaveCurves()

static private byte smoothLine = (byte)MILCoreSegFlags.SegTypeLine | (byte)MILCoreSegFlags.SegSmoothJoin;

static private byte[] s_roundedPathTypes = {
(byte)MILCoreSegFlags.SegTypeBezier |
private static ReadOnlySpan<byte> RoundedPathTypes => new byte[] {
(byte)MILCoreSegFlags.SegTypeBezier |
(byte)MILCoreSegFlags.SegIsCurved |
(byte)MILCoreSegFlags.SegSmoothJoin |
(byte)MILCoreSegFlags.SegSmoothJoin |
(byte)MILCoreSegFlags.SegClosed,
smoothLine,
smoothLine,
smoothBezier,
smoothLine,
smoothLine,
smoothBezier,
smoothLine,
smoothLine,
smoothBezier,
smoothLine
smoothLine
};

// Squared
private const UInt32 c_squaredSegmentCount = 4;
private const UInt32 c_squaredPointCount = 5;

private static readonly byte[] s_squaredPathTypes = {
(byte)MILCoreSegFlags.SegTypeLine | (byte)MILCoreSegFlags.SegClosed,
(byte)MILCoreSegFlags.SegTypeLine,
(byte)MILCoreSegFlags.SegTypeLine,
(byte)MILCoreSegFlags.SegTypeLine
};
private static ReadOnlySpan<byte> SquaredPathTypes => [(byte)MILCoreSegFlags.SegTypeLine | (byte)MILCoreSegFlags.SegClosed,
(byte)MILCoreSegFlags.SegTypeLine,
(byte)MILCoreSegFlags.SegTypeLine,
(byte)MILCoreSegFlags.SegTypeLine];

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ private class ResolvingLocatorState
private Hashtable _selectionProcessors;

// Potential separators for subtree processor class names
private static readonly Char[] Separators = new Char[] { ',', ' ', ';' };
private static ReadOnlySpan<char> Separators => [',', ' ', ';'];

// Optional store, used if passed in, otherwise we grab the service's store
private AnnotationStore _internalStore = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ private static bool IsKnownIndexMarkerStyle(TextMarkerStyle markerStyle)
new string[] { "M??", "CDM", "XLC", "IVX" }
};

private static int[] RomanNumericSizeIncrements =
new int[] { 1, 2, 3, 8, 18, 28, 38, 88, 188, 288, 388, 888 };
private static ReadOnlySpan<int> RomanNumericSizeIncrements => [1, 2, 3, 8, 18, 28, 38, 88, 188, 288, 388, 888];
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static DataGridLength ConvertFromString(string s, CultureInfo cultureInf
if (goodString.EndsWith(unitString, StringComparison.Ordinal))
{
strLenUnit = unitString.Length;
unitFactor = _pixelUnitFactors[i];
unitFactor = PixelUnitFactors[i];
break;
}
}
Expand Down Expand Up @@ -281,11 +281,11 @@ private static DataGridLength ConvertFromString(string s, CultureInfo cultureInf
private static string[] _nonStandardUnitStrings = { "in", "cm", "pt" };

// These are conversion factors to transform other units to pixels
private static double[] _pixelUnitFactors =
{
private static ReadOnlySpan<double> PixelUnitFactors =>
[
96.0, // Pixels per Inch
96.0 / 2.54, // Pixels per Centimeter
96.0 / 72.0, // Pixels per Point
};
];
}
}
Loading