diff --git a/src/Microsoft.DotNet.Wpf/src/Common/Graphics/wgx_exports.cs b/src/Microsoft.DotNet.Wpf/src/Common/Graphics/wgx_exports.cs index 2cb3cdc0fbf..bb8dbbaca2a 100644 --- a/src/Microsoft.DotNet.Wpf/src/Common/Graphics/wgx_exports.cs +++ b/src/Microsoft.DotNet.Wpf/src/Common/Graphics/wgx_exports.cs @@ -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 GUID_VendorMicrosoft => [0xca, 0x49, 0xe7, 0xf0, 0xef, 0xed, 0x89, 0x45, 0xa7, 0x3a, 0xee, 0xe, 0x62, 0x6a, 0x2a, 0x2b]; } #endregion // Guids } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs index 9dc4f1b7843..b282d5c4c2a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs @@ -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())) { // // @@ -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 diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/AlgoModule.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/AlgoModule.cs index 7bcd243b322..a2ec23b29c3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/AlgoModule.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/AlgoModule.cs @@ -457,7 +457,7 @@ private LZCodec LZCodec internal const byte DefaultBAACount = 8; internal const byte MaxBAACount = 10; + private static ReadOnlySpan DefaultFirstSquareRoot => [1, 1, 1, 4, 9, 16, 36, 49]; - private static readonly double[] DefaultFirstSquareRoot = { 1, 1, 1, 4, 9, 16, 36, 49}; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs index 8fec30aa336..0d480c0a228 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs @@ -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 Base64HeaderBytes => [(byte)'b', + (byte)'a', + (byte)'s', + (byte)'e', + (byte)'6', + (byte)'4', + (byte)':']; #if OLD_ISF /// @@ -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; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Shaping/Positioning.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Shaping/Positioning.cs index fa86f25f03d..a5b3d4f7ff4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Shaping/Positioning.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Shaping/Positioning.cs @@ -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 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, diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs index 4047af68793..7d8204a1a0e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs @@ -354,7 +354,7 @@ private bool IsValidCursorType(CursorType cursorType) private SafeHandle _cursorHandle; - private static readonly int[] CursorTypes = { + private static ReadOnlySpan CursorTypes => [ 0, // None NativeMethods.IDC_NO, NativeMethods.IDC_ARROW, @@ -383,6 +383,6 @@ private bool IsValidCursorType(CursorType cursorType) NativeMethods.IDC_ARROW + 149, // ScrollSWCursor NativeMethods.IDC_ARROW + 150, // ScrollSECursor NativeMethods.IDC_ARROW + 151 // ArrowCDCursor - }; + ]; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/EllipseGeometry.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/EllipseGeometry.cs index 6d206f8357a..b67934e4b30 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/EllipseGeometry.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/EllipseGeometry.cs @@ -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, @@ -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, @@ -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 @@ -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 RoundedPathTypes => [(byte)MILCoreSegFlags.SegTypeBezier | + (byte)MILCoreSegFlags.SegIsCurved | + (byte)MILCoreSegFlags.SegSmoothJoin | + (byte)MILCoreSegFlags.SegClosed, + c_smoothBezier, + c_smoothBezier, + c_smoothBezier]; #endregion } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/LineGeometry.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/LineGeometry.cs index e30c2833faa..93e1d68afe4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/LineGeometry.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/LineGeometry.cs @@ -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, @@ -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, @@ -185,13 +185,11 @@ public override double GetArea(double tolerance, ToleranceType type) return 0.0; } - private byte[] GetTypeList() { return s_lineTypes; } + private static ReadOnlySpan 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; } /// /// GetAsPathGeometry - return a PathGeometry version of this Geometry diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/RectangleGeometry.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/RectangleGeometry.cs index 5d0daeb910b..5c6316dc425 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/RectangleGeometry.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/RectangleGeometry.cs @@ -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, @@ -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, @@ -510,7 +510,7 @@ private unsafe static void GetPointList(Point * points, uint pointsCount, Rect r } } - private static byte[] GetTypeList(Rect rect, double radiusX, double radiusY) + private static ReadOnlySpan GetTypeList(Rect rect, double radiusX, double radiusY) { if (rect.IsEmpty) { @@ -518,11 +518,11 @@ private static byte[] GetTypeList(Rect rect, double radiusX, double radiusY) } else if (IsRounded(radiusX, radiusY)) { - return s_roundedPathTypes; + return RoundedPathTypes; } else { - return s_squaredPathTypes; + return SquaredPathTypes; } } @@ -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 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 SquaredPathTypes => [(byte)MILCoreSegFlags.SegTypeLine | (byte)MILCoreSegFlags.SegClosed, + (byte)MILCoreSegFlags.SegTypeLine, + (byte)MILCoreSegFlags.SegTypeLine, + (byte)MILCoreSegFlags.SegTypeLine]; #endregion } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/LocatorManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/LocatorManager.cs index f9d74d25c2d..c480add7f71 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/LocatorManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/LocatorManager.cs @@ -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 Separators => [',', ' ', ';']; // Optional store, used if passed in, otherwise we grab the service's store private AnnotationStore _internalStore = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ListMarkerSourceInfo.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ListMarkerSourceInfo.cs index d78ea8ffd69..f23fbe35087 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ListMarkerSourceInfo.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ListMarkerSourceInfo.cs @@ -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 RomanNumericSizeIncrements => [1, 2, 3, 8, 18, 28, 38, 88, 188, 288, 388, 888]; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs index 2cfcdf3de3d..fe7cec60126 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs @@ -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; } } @@ -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 PixelUnitFactors => + [ 96.0, // Pixels per Inch 96.0 / 2.54, // Pixels per Centimeter 96.0 / 72.0, // Pixels per Point - }; + ]; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs index 84eaddf6bec..f9ee842f9ed 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs @@ -44,7 +44,7 @@ public class DataGridRow : Control private const byte DATAGRIDROW_stateNullCode = 255; // Static arrays to handle state transitions: - private static byte[] _idealStateMapping = new byte[] { + private static ReadOnlySpan IdealStateMapping => [ DATAGRIDROW_stateNormalCode, DATAGRIDROW_stateNormalCode, DATAGRIDROW_stateMouseOverCode, @@ -61,9 +61,9 @@ public class DataGridRow : Control DATAGRIDROW_stateNormalEditingFocusedCode, DATAGRIDROW_stateMouseOverEditingCode, DATAGRIDROW_stateMouseOverEditingFocusedCode - }; + ]; - private static byte[] _fallbackStateMapping = new byte[] { + private static ReadOnlySpan FallbackStateMapping => [ DATAGRIDROW_stateNormalCode, //DATAGRIDROW_stateMouseOverCode's fallback DATAGRIDROW_stateMouseOverEditingFocusedCode, //DATAGRIDROW_stateMouseOverEditingCode's fallback DATAGRIDROW_stateNormalEditingFocusedCode, //DATAGRIDROW_stateMouseOverEditingFocusedCode's fallback @@ -74,7 +74,7 @@ public class DataGridRow : Control DATAGRIDROW_stateSelectedFocusedCode, //DATAGRIDROW_stateNormalEditingFocusedCode's fallback DATAGRIDROW_stateSelectedFocusedCode, //DATAGRIDROW_stateSelectedCode's fallback DATAGRIDROW_stateNormalCode //DATAGRIDROW_stateSelectedFocusedCode's fallback - }; + ]; private static string[] _stateNames = new string[] { VisualStates.DATAGRIDROW_stateMouseOver, @@ -226,7 +226,7 @@ internal override void ChangeVisualState(bool useTransitions) idealStateMappingIndex += 1; } - byte stateCode = _idealStateMapping[idealStateMappingIndex]; + byte stateCode = IdealStateMapping[idealStateMappingIndex]; Debug.Assert(stateCode != DATAGRIDROW_stateNullCode); string storyboardName; @@ -254,7 +254,7 @@ internal override void ChangeVisualState(bool useTransitions) else { // The state wasn't implemented so fall back to the next one - stateCode = _fallbackStateMapping[stateCode]; + stateCode = FallbackStateMapping[stateCode]; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs index 16796987037..155e781f8fc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs @@ -1185,7 +1185,7 @@ protected virtual void OnIncreaseZoomCommand() // Set the zoom percentage, with _updatingInternalZoomLevel set to true to // avoid resetting the zoom level index. _updatingInternalZoomLevel = true; - Zoom = DocumentViewer._zoomLevelCollection[_zoomLevelIndex]; + Zoom = ZoomLevelCollection[_zoomLevelIndex]; _updatingInternalZoomLevel = false; } } @@ -1203,8 +1203,8 @@ protected virtual void OnDecreaseZoomCommand() FindZoomLevelIndex(); // If the current zoom value exists in the zoomLevelCollection, and can // still be zoomed out, then zoom out another level. - if ((oldZoom == DocumentViewer._zoomLevelCollection[_zoomLevelIndex]) && - (_zoomLevelIndex < DocumentViewer._zoomLevelCollection.Length - 1)) + if ((oldZoom == ZoomLevelCollection[_zoomLevelIndex]) && + (_zoomLevelIndex < ZoomLevelCollection.Length - 1)) { _zoomLevelIndex++; } @@ -1212,7 +1212,7 @@ protected virtual void OnDecreaseZoomCommand() // Set the zoom percentage, with _updatingInternalZoomLevel set to true to // avoid resetting the zoom level index. _updatingInternalZoomLevel = true; - Zoom = _zoomLevelCollection[_zoomLevelIndex]; + Zoom = ZoomLevelCollection[_zoomLevelIndex]; _updatingInternalZoomLevel = false; } } @@ -2287,45 +2287,41 @@ private KeyEventArgs ProcessFindKeys(KeyEventArgs e) /// private void FindZoomLevelIndex() { - // Ensure the list of zoom levels is created. - if (_zoomLevelCollection != null) + // If the index is not in a valid location, update it to the list start. + if ((_zoomLevelIndex < 0) || (_zoomLevelIndex >= ZoomLevelCollection.Length)) { - // If the index is not in a valid location, update it to the list start. - if ((_zoomLevelIndex < 0) || (_zoomLevelIndex >= _zoomLevelCollection.Length)) - { - _zoomLevelIndex = 0; - _zoomLevelIndexValid = false; - } + _zoomLevelIndex = 0; + _zoomLevelIndexValid = false; + } + + // Check if the current index is in the correct location in the list. + if (!_zoomLevelIndexValid) + { + // Since the index is not in the correct location in the list + // (ie the Zoom was set by another means), then + // search the list of possible zooms for the correct location. + double currentZoom = Zoom; + + // Currently this search is done using a linear method which is + // fine given the small size of the list. If we increase the list + // size, then a simple binary search could increaes performance. - // Check if the current index is in the correct location in the list. - if (!_zoomLevelIndexValid) + // Search the list of zoom's from highest to lowest until the + // appropriate "floor" level (level equal to, or + // lower than the current zoom) is found. + int loopIndex; + for (loopIndex = 0; loopIndex < ZoomLevelCollection.Length - 1; loopIndex++) { - // Since the index is not in the correct location in the list - // (ie the Zoom was set by another means), then - // search the list of possible zooms for the correct location. - double currentZoom = Zoom; - - // Currently this search is done using a linear method which is - // fine given the small size of the list. If we increase the list - // size, then a simple binary search could increaes performance. - - // Search the list of zoom's from highest to lowest until the - // appropriate "floor" level (level equal to, or - // lower than the current zoom) is found. - int loopIndex; - for (loopIndex = 0; loopIndex < _zoomLevelCollection.Length - 1; loopIndex++) + if (currentZoom >= ZoomLevelCollection[loopIndex]) { - if (currentZoom >= _zoomLevelCollection[loopIndex]) - { - // Closest equal or lower match found - break; - } + // Closest equal or lower match found + break; } - // Assign the current zoom level, and mark that our index is valid - // (for future Increase / Decrease zoom calls). - _zoomLevelIndex = loopIndex; - _zoomLevelIndexValid = true; } + // Assign the current zoom level, and mark that our index is valid + // (for future Increase / Decrease zoom calls). + _zoomLevelIndex = loopIndex; + _zoomLevelIndexValid = true; } } @@ -2658,9 +2654,9 @@ private static void OnHorizontalPageSpacingChanged(DependencyObject d, Dependenc private static RoutedUICommand _fitToMaxPagesAcrossCommand; // This list is assumed to be in decreasing order. - private static double[] _zoomLevelCollection = {5000.0, 4000.0, 3200.0, 2400.0, 2000.0, 1600.0, - 1200.0, 800.0, 400.0, 300.0, 200.0, 175.0, 150.0, - 125.0, 100.0, 75.0, 66.0, 50.0, 33.0, 25.0, 10.0, 5.0}; + private static ReadOnlySpan ZoomLevelCollection => [5000.0, 4000.0, 3200.0, 2400.0, 2000.0, 1600.0, + 1200.0, 800.0, 400.0, 300.0, 200.0, 175.0, 150.0, + 125.0, 100.0, 75.0, 66.0, 50.0, 33.0, 25.0, 10.0, 5.0]; private int _zoomLevelIndex; // = 0 private bool _zoomLevelIndexValid; // = false private bool _updatingInternalZoomLevel; // = false diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs index 760baaf69b9..a633631a4a2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs @@ -42,7 +42,7 @@ public class DataGridRowHeader : ButtonBase private const byte DATAGRIDROWHEADER_stateSelectedFocusedCode = 15; private const byte DATAGRIDROWHEADER_stateNullCode = 255; - private static byte[] _fallbackStateMapping = new byte[] { + private static ReadOnlySpan FallbackStateMapping => [ DATAGRIDROWHEADER_stateNormalCode, DATAGRIDROWHEADER_stateNormalCurrentRowCode, DATAGRIDROWHEADER_stateMouseOverEditingRowFocusedCode, @@ -59,9 +59,9 @@ public class DataGridRowHeader : ButtonBase DATAGRIDROWHEADER_stateSelectedCurrentRowFocusedCode, DATAGRIDROWHEADER_stateNormalCurrentRowCode, DATAGRIDROWHEADER_stateNormalCode, - }; + ]; - private static byte[] _idealStateMapping = new byte[] { + private static ReadOnlySpan IdealStateMapping => [ DATAGRIDROWHEADER_stateNormalCode, DATAGRIDROWHEADER_stateNormalCode, DATAGRIDROWHEADER_stateMouseOverCode, @@ -94,7 +94,7 @@ public class DataGridRowHeader : ButtonBase DATAGRIDROWHEADER_stateNormalEditingRowFocusedCode, DATAGRIDROWHEADER_stateMouseOverEditingRowCode, DATAGRIDROWHEADER_stateMouseOverEditingRowFocusedCode - }; + ]; private static string[] _stateNames = new string[] { @@ -490,7 +490,7 @@ internal override void ChangeVisualState(bool useTransitions) idealStateMappingIndex += 1; } - byte stateCode = _idealStateMapping[idealStateMappingIndex]; + byte stateCode = IdealStateMapping[idealStateMappingIndex]; Debug.Assert(stateCode != DATAGRIDROWHEADER_stateNullCode); string storyboardName; @@ -504,7 +504,7 @@ internal override void ChangeVisualState(bool useTransitions) else { // The state wasn't implemented so fall back to the next one - stateCode = _fallbackStateMapping[stateCode]; + stateCode = FallbackStateMapping[stateCode]; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs index 7813a57b87e..5f62fd2086d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs @@ -91,8 +91,8 @@ internal static bool AlwaysAdjacent(CultureInfo ci) // NOTE it is okay to not getting accurate list as long as // we deal with common cases since this is used in heuristic // algorithm! - internal static char[] HyphenSet = - { + internal static ReadOnlySpan HyphenSet => + [ '\x002D', // Hyphen-Minus '\x2010', // Hyphen '\x2011', // Non-breaking Hyphen @@ -100,19 +100,9 @@ internal static bool AlwaysAdjacent(CultureInfo ci) '\x2013', // En-dash '\x2212', // Minus Sign '\x00AD' // Soft-Hyphen - }; + ]; - internal static bool IsHyphen(char target) - { - foreach (char hyphen in HyphenSet) - { - if (hyphen == target) - { - return true; - } - } - return false; - } + internal static bool IsHyphen(char target) => HyphenSet.Contains(target); // Space that was used in the heuristic algorithm. internal static bool IsSpace(char target) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs index 059ab63d990..62d99b4a87e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs @@ -4581,8 +4581,7 @@ internal class DocumentNode "td" }; - internal static int[] HtmlLengths = new int[] - { + internal static ReadOnlySpan HtmlLengths => [ 0, // unknown 0, // text 4, // span @@ -4595,7 +4594,7 @@ internal class DocumentNode 6, // tbody 2, // tr 2 // td - }; + ]; internal static string[] XamlNames = new string[] { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs index 00f11d0553b..fc810416001 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs @@ -1246,7 +1246,7 @@ internal string _FilterText(string textData, int charsToReplaceCount, bool filte { textData = textData.Substring(0, endOfFirstLine); } - endOfFirstLine = textData.IndexOfAny(TextPointerBase.NextLineCharacters); + endOfFirstLine = textData.AsSpan().IndexOfAny(TextPointerBase.NextLineCharacters); if (endOfFirstLine >= 0) { textData = textData.Substring(0, endOfFirstLine); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextPointerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextPointerBase.cs index b5583b509e8..8d335bf8383 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextPointerBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextPointerBase.cs @@ -637,13 +637,10 @@ internal static bool IsNextToPlainLineBreak(ITextPointer thisPosition, LogicalDi // Following Unicode newline guideline from http://www.unicode.org/unicode/standard/reports/tr13/tr13-5.html // To the standard list requirements we added '\v' and '\f' - internal static Char[] NextLineCharacters = new char[] { '\n', '\r', '\v', '\f', '\u0085' /*NEL*/, '\u2028' /*LS*/, '\u2029' /*PS*/ }; + internal static ReadOnlySpan NextLineCharacters => ['\n', '\r', '\v', '\f', '\u0085' /*NEL*/, '\u2028' /*LS*/, '\u2029' /*PS*/]; // Returns true if a specified char matches the Unicode definition of "newline". - internal static bool IsCharUnicodeNewLine(char ch) - { - return Array.IndexOf(NextLineCharacters, ch) > -1; - } + internal static bool IsCharUnicodeNewLine(char ch) => NextLineCharacters.Contains(ch); /// /// Returns true if the position is adjacent to a LineBreak element, diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs index e25915fd9da..378af8ae8ff 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs @@ -35,7 +35,7 @@ internal static class KnownStrings public const string DefaultPrefix = "p"; public const string ReferenceName = "__ReferenceID"; - public static readonly char[] WhitespaceChars = new char[] { ' ', '\t', '\n', '\r', '\f' }; + public static ReadOnlySpan WhitespaceChars => [' ', '\t', '\n', '\r', '\f']; public const char SpaceChar = ' '; public const char TabChar = '\t'; public const char NewlineChar = '\n'; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinEventTracker.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinEventTracker.cs index 7b2c4fa3108..7bdd1c728f3 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinEventTracker.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinEventTracker.cs @@ -199,7 +199,7 @@ private static void StopListening (ref EventHookParams hp) // to find a match. // Call the delegate associated with the hwnd to create a raw element. // Call the automation code to queue a new notification for the client. - private static void WinEventProc (int winEventHook, int eventId, IntPtr hwnd, int idObject, int idChild, int eventThread, uint eventTime) + private static void WinEventProc(int winEventHook, int eventId, IntPtr hwnd, int idObject, int idChild, int eventThread, uint eventTime) { if (hwnd == IntPtr.Zero) { @@ -210,7 +210,7 @@ private static void WinEventProc (int winEventHook, int eventId, IntPtr hwnd, in try { - int evt = Array.BinarySearch(_eventIdToIndex, eventId); + int evt = EventIdToIndex.BinarySearch(eventId); if (evt < 0) return; // negative means this event is unknown so ignore it @@ -353,7 +353,7 @@ private static void BuildEventsList (EventFlag eFlag, IntPtr hwnd, ProxyRaiseEve EvtIdProperty evtIdProp = aEvtIdProp[i]; // Map a property into a WinEventHookProperty - int evt = Array.BinarySearch (_eventIdToIndex, evtIdProp._evtId); + int evt = EventIdToIndex.BinarySearch(evtIdProp._evtId); // add the window to the list if (evt >= 0) @@ -532,7 +532,7 @@ private enum EventFlag } // Maps WinEvents ID to indices in _ahp - private static readonly int[] _eventIdToIndex = new int[] { + private static ReadOnlySpan EventIdToIndex => [ NativeMethods.EventSystemSound, NativeMethods.EventSystemAlert, NativeMethods.EventSystemForeground, @@ -584,7 +584,7 @@ private enum EventFlag NativeMethods.EventObjectAcceleratorChange, NativeMethods.EventObjectInvoke, NativeMethods.EventObjectTextSelectionChanged - }; + ]; // WinEventHooks must be processed in the same thread that created them. // Use a seperate thread to manage the hooks @@ -596,7 +596,7 @@ private enum EventFlag // Each element in the array list is a struct EventCreateParams that contains // the hwnd and the other parameters needed to call the Proxy and then // the client notification - private static Hashtable[] _ahp = new Hashtable[_eventIdToIndex.Length]; + private static Hashtable[] _ahp = new Hashtable[EventIdToIndex.Length]; private static uint _globalEventKey = 0; diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs index 1f76ecc6a70..1a54d282157 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs @@ -288,9 +288,9 @@ public override string ToString() { foreach (string paramterKey in _parameterDictionary.Keys) { - stringBuilder.Append(_LinearWhiteSpaceChars[0]); + stringBuilder.Append(LinearWhiteSpaceChars[0]); stringBuilder.Append(_semicolonSeparator); - stringBuilder.Append(_LinearWhiteSpaceChars[0]); + stringBuilder.Append(LinearWhiteSpaceChars[0]); stringBuilder.Append(paramterKey); stringBuilder.Append(_equalSeparator); stringBuilder.Append(_parameterDictionary[paramterKey]); @@ -400,13 +400,13 @@ private static void ValidateCarriageReturns(string contentType) //character of the content type are not Linear White Spaces. So its safe to //assume that the index will be greater than 0 and less that length-2. - int index = contentType.IndexOf(_LinearWhiteSpaceChars[2]); + int index = contentType.IndexOf(LinearWhiteSpaceChars[2]); while (index != -1) { - if (contentType[index - 1] == _LinearWhiteSpaceChars[1] || contentType[index + 1] == _LinearWhiteSpaceChars[1]) + if (contentType[index - 1] == LinearWhiteSpaceChars[1] || contentType[index + 1] == LinearWhiteSpaceChars[1]) { - index = contentType.IndexOf(_LinearWhiteSpaceChars[2], ++index); + index = contentType.IndexOf(LinearWhiteSpaceChars[2], ++index); } else throw new ArgumentException(SR.InvalidLinearWhiteSpaceCharacter); @@ -422,7 +422,7 @@ private static void ValidateCarriageReturns(string contentType) private void ParseTypeAndSubType(ReadOnlySpan typeAndSubType) { //okay to trim at this point the end of the string as Linear White Spaces(LWS) chars are allowed here. - typeAndSubType = typeAndSubType.TrimEnd(_LinearWhiteSpaceChars); + typeAndSubType = typeAndSubType.TrimEnd(LinearWhiteSpaceChars); int forwardSlashPos = typeAndSubType.IndexOf('/'); if (forwardSlashPos < 0 || // no slashes @@ -461,7 +461,7 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) //okay to trim start as there can be spaces before the begining //of the parameter name. - parameterAndValue = parameterAndValue.TrimStart(_LinearWhiteSpaceChars); + parameterAndValue = parameterAndValue.TrimStart(LinearWhiteSpaceChars); int equalSignIndex = parameterAndValue.IndexOf(_equalSeparator); @@ -479,7 +479,7 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) ValidateToken(parameterAndValue.Slice(0, equalSignIndex).ToString()), ValidateQuotedStringOrToken(parameterAndValue.Slice(parameterStartIndex, parameterValueLength).ToString())); - parameterAndValue = parameterAndValue.Slice(parameterStartIndex + parameterValueLength).TrimStart(_LinearWhiteSpaceChars); + parameterAndValue = parameterAndValue.Slice(parameterStartIndex + parameterValueLength).TrimStart(LinearWhiteSpaceChars); } } @@ -502,7 +502,7 @@ private static int GetLengthOfParameterValue(ReadOnlySpan s, int startInde if (semicolonIndex != -1) { - int lwsIndex = s.Slice(startIndex).IndexOfAny(_LinearWhiteSpaceChars); + int lwsIndex = s.Slice(startIndex).IndexOfAny(LinearWhiteSpaceChars); length = lwsIndex != -1 && lwsIndex < semicolonIndex ? lwsIndex : semicolonIndex; length += startIndex; // the indexes from IndexOf{Any} are based on slicing from startIndex } @@ -617,17 +617,7 @@ private static void ValidateQuotedText(ReadOnlySpan quotedText) /// /// input character /// - private static bool IsAllowedCharacter(char character) - { - //We did not use any of the .Contains methods as - //it will result in boxing costs. - foreach (char c in _allowedCharacters) - { - if (c == character) - return true; - } - return false; - } + private static bool IsAllowedCharacter(char character) => AllowedCharacters.Contains(character); /// /// Returns true if the input character is an ASCII digit or letter @@ -646,21 +636,7 @@ private static bool IsAsciiLetterOrDigit(char character) => /// /// input character /// - private static bool IsLinearWhiteSpaceChar(char ch) - { - if (ch > ' ') - { - return false; - } - - foreach (char c in _LinearWhiteSpaceChars) - { - if (ch == c) - return true; - } - - return false; - } + private static bool IsLinearWhiteSpaceChar(char ch) => LinearWhiteSpaceChars.Contains(ch); /// /// Lazy initialization for the ParameterDictionary @@ -694,21 +670,21 @@ private void EnsureParameterDictionary() private const char _equalSeparator = '='; //This array is sorted by the ascii value of these characters. - private static readonly char[] _allowedCharacters = - { '!' /*33*/, '#' /*35*/ , '$' /*36*/, + private static ReadOnlySpan AllowedCharacters => [ + '!' /*33*/, '#' /*35*/ , '$' /*36*/, '%' /*37*/, '&' /*38*/ , '\'' /*39*/, '*' /*42*/, '+' /*43*/ , '-' /*45*/, '.' /*46*/, '^' /*94*/ , '_' /*95*/, '`' /*96*/, '|' /*124*/, '~' /*126*/, - }; + ]; //Linear White Space characters - private static readonly char[] _LinearWhiteSpaceChars = - { ' ', // space - \x20 + private static ReadOnlySpan LinearWhiteSpaceChars => [ + ' ', // space - \x20 '\n', // new line - \x0A '\r', // carriage return - \x0D '\t' // horizontal tab - \x09 - }; + ]; private static readonly ContentType _emptyContentType = new ContentType(""); diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs index 1fe3aa32e52..c10a551119d 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs @@ -1302,7 +1302,7 @@ BinaryWriter writer if (extra != 0) { // No need to use checked{} here since we already made sure that extra is smaller than Int32Size - writer.Write(Padding, 0, CU.Int32Size - extra); + writer.Write(Padding.Slice(0, CU.Int32Size - extra)); } } @@ -1435,16 +1435,15 @@ Encoding encoding // private const int MaxPublishLicenseHeaderLen = 4096; - private static readonly char[] Base32EncodingTable = { + private static ReadOnlySpan Base32EncodingTable => [ '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', - '2', '3', '4', '5', '6', '7', '=' - }; + '2', '3', '4', '5', '6', '7', '=']; // // Used to DWORD-align a stream after writing a string to it: // - private static readonly byte[] Padding = {0, 0, 0}; + private static ReadOnlySpan Padding => [0, 0, 0]; private const int SizeofByte = 1; diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs index 526dcae974e..9d61276a767 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs @@ -497,7 +497,7 @@ private bool IsRelationshipUri() // of .rels. The folder must also be the last "folder". // Comparing using the normalized string to reduce the number of ToUpperInvariant operations // required for case-insensitive comparison - string[] segments = NormalizedPartUriString.Split(_forwardSlashSeparator); //new Uri(_defaultUri, this).Segments; //partUri.Segments cannot be called on a relative Uri; + string[] segments = NormalizedPartUriString.Split(ForwardSlashSeparator); //new Uri(_defaultUri, this).Segments; //partUri.Segments cannot be called on a relative Uri; // String.Split, will always return an empty string as the // first member in the array as the string starts with a "/" @@ -591,7 +591,7 @@ private int Compare(ValidatedPartUri otherPartUri) false /*computeIsRelationship*/, true /*IsRelationship*/); - private static readonly char[] _forwardSlashSeparator = { '/' }; + private static ReadOnlySpan ForwardSlashSeparator => ['/']; #endregion Private Methods