From 01bcbd5691b23085eb8cd75f944ecae39e9f633c Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Sat, 11 Jan 2025 22:10:04 +0100 Subject: [PATCH 1/3] Avoid zero-length array allocations --- src/Microsoft.DotNet.Wpf/src/.editorconfig | 3 --- .../MS/Internal/MarkupCompiler/MarkupCompiler.cs | 6 ++---- .../Generated/WinRT/GuidGenerator.cs | 2 +- .../Automation/Peers/GridViewAutomationPeer.cs | 2 +- .../System/Windows/Controls/InkCanvas.cs | 6 +++--- .../System/Windows/Controls/Slider.cs | 2 +- .../System/Windows/Documents/TextSchema.cs | 7 ++----- .../System/Windows/Markup/XamlTypeMapper.cs | 9 ++------- .../MS/Internal/Automation/Schema.cs | 14 +++++++------- .../MS/Internal/Automation/UiaCoreApi.cs | 6 +++--- .../System/Windows/Automation/CacheRequest.cs | 2 +- .../AutomationProxies/MSAANativeProvider.cs | 2 +- .../Internal/AutomationProxies/WindowsRichEdit.cs | 4 ++-- .../System/Windows/Automation/ControlType.cs | 8 ++++---- 14 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/.editorconfig b/src/Microsoft.DotNet.Wpf/src/.editorconfig index 2ea8e052b1e..a1e62a5e1d7 100644 --- a/src/Microsoft.DotNet.Wpf/src/.editorconfig +++ b/src/Microsoft.DotNet.Wpf/src/.editorconfig @@ -95,9 +95,6 @@ dotnet_diagnostic.CA1822.severity = suggestion # CA1823: Avoid unused private fields dotnet_diagnostic.CA1823.severity = suggestion -# CA1825: Avoid zero-length array allocations -dotnet_diagnostic.CA1825.severity = suggestion - # CA1834: Use StringBuilder.Append(char) for single character strings dotnet_diagnostic.CA1834.severity = suggestion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs index c0a0ec5a2af..b6e85e5da31 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs @@ -982,11 +982,10 @@ internal void ConnectStyleEvent(XamlClrEventNode xamlClrEventNode) // eventSetter = new EventSetter(); // - CodeExpression[] esParams = {}; CodeVariableReferenceExpression cvreES = new CodeVariableReferenceExpression(EVENTSETTER); CodeAssignStatement casES = new CodeAssignStatement(cvreES, new CodeObjectCreateExpression(KnownTypes.Types[(int)KnownElements.EventSetter], - esParams)); + Array.Empty())); // eventSetter.Event = Button.ClickEvent; // @@ -3160,9 +3159,8 @@ private CodeVariableReferenceExpression GenerateAppInstance(CodeMemberMethod cmm // CodeObjectCreateExpression coce; CodeVariableReferenceExpression cvre = new CodeVariableReferenceExpression(APPVAR); - CodeExpression[] ctorParams = {}; - coce = new CodeObjectCreateExpression(appClassName, ctorParams); + coce = new CodeObjectCreateExpression(appClassName, Array.Empty()); CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement(appClassName, APPVAR, coce); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/GuidGenerator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/GuidGenerator.cs index e6e146f6229..93e5e781b14 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/GuidGenerator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/GuidGenerator.cs @@ -33,7 +33,7 @@ public static string GetSignature(Type type) var sigMethod = helperType.GetMethod("GetGuidSignature", BindingFlags.Static | BindingFlags.Public); if (sigMethod != null) { - return (string)sigMethod.Invoke(null, new Type[] { }); + return (string)sigMethod.Invoke(null, Array.Empty()); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewAutomationPeer.cs index f1e215587a9..adef4ca8521 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewAutomationPeer.cs @@ -147,7 +147,7 @@ IRawElementProviderSimple[] ITableProvider.GetColumnHeaders() return array.ToArray(); } - return new IRawElementProviderSimple[0] ; + return Array.Empty(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs index 91ceb2d4d93..27297d76802 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs @@ -2309,7 +2309,7 @@ internal bool ClearSelectionRaiseSelectionChanging() // // attempt to clear selection // - ChangeInkCanvasSelection(new StrokeCollection(), new UIElement[]{}); + ChangeInkCanvasSelection(new StrokeCollection(), Array.Empty()); return !InkCanvasSelection.HasSelection; } @@ -2325,7 +2325,7 @@ internal void ClearSelection(bool raiseSelectionChangedEvent) if ( InkCanvasSelection.HasSelection ) { // Reset the current selection - CoreChangeSelection(new StrokeCollection(), new UIElement[] { }, raiseSelectionChangedEvent); + CoreChangeSelection(new StrokeCollection(), Array.Empty(), raiseSelectionChangedEvent); } } @@ -2510,7 +2510,7 @@ private UIElement[] ValidateSelectedElements(IEnumerable selectedElem { if (selectedElements == null) { - return new UIElement[]{}; + return Array.Empty(); } List elements = new List(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs index ab9ac3ce50d..8de1844cc86 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs @@ -966,7 +966,7 @@ private CustomPopupPlacement[] AutoToolTipCustomPlacementCallback(Size popupSize } default: - return new CustomPopupPlacement[]{}; + return Array.Empty(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSchema.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSchema.cs index 6cf37435da2..1d5171eab46 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSchema.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSchema.cs @@ -502,7 +502,7 @@ internal static DependencyProperty[] GetNoninheritableProperties(Type type) } else if (typeof(LineBreak).IsAssignableFrom(type)) { - return _emptyPropertyList; + return Array.Empty(); } else if (typeof(Floater).IsAssignableFrom(type)) { @@ -560,7 +560,7 @@ internal static DependencyProperty[] GetNoninheritableProperties(Type type) } Invariant.Assert(false, "We do not expect any unknown elements derived directly from TextElement. Schema must have been checking for that"); - return _emptyPropertyList; // to make compiler happy + return Array.Empty(); // to make compiler happy } // Compares two values for equality @@ -1202,9 +1202,6 @@ private static bool AreBrushesEqual(Brush brush1, Brush brush2) UIElement.AllowDropProperty, }; - // Empty property list - private static readonly DependencyProperty[] _emptyPropertyList = new DependencyProperty[] { }; - // Structural property list. // NB: Existing code depends on these being inheritable properties. private static readonly DependencyProperty[] _structuralCharacterProperties = new DependencyProperty[] diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs index ad62adecc06..428817826c4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs @@ -4432,7 +4432,7 @@ internal static string[] GetDefaultAssemblyNames() /// internal static NamespaceMapEntry[] GetDefaultNamespaceMaps() { - return (NamespaceMapEntry[])_defaultNamespaceMapTable.Clone(); + return Array.Empty(); } #endregion Properties @@ -4440,12 +4440,7 @@ internal static NamespaceMapEntry[] GetDefaultNamespaceMaps() #region Data // array of our defaultAssemblies. - private static readonly string[] _defaultAssemblies = {"WindowsBase", "PresentationCore", "PresentationFramework"}; - - // array of namespaceMaps the map an xmlns namespaceURI - // to the assembly and urtNamespace to search in when resolving the xml - - private static readonly NamespaceMapEntry[] _defaultNamespaceMapTable = { }; + private static readonly string[] _defaultAssemblies = { "WindowsBase", "PresentationCore", "PresentationFramework" }; #endregion Data } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Schema.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Schema.cs index 7b11947cb45..36dba1a4eff 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Schema.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Schema.cs @@ -1,9 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. // Description: property/pattern/event information +using System; using System.Windows; using System.Windows.Automation; using System.Windows.Automation.Text; @@ -338,7 +338,7 @@ private static object ConvertToAutomationHeadingLevel(object value) new AutomationPropertyInfo( null, ScrollPattern.VerticalViewSizeProperty, typeof(double), (double)100 ), new AutomationPropertyInfo( convertToBool, ScrollPattern.HorizontallyScrollableProperty, typeof(bool), false ), new AutomationPropertyInfo( convertToBool, ScrollPattern.VerticallyScrollableProperty, typeof(bool), false ), - new AutomationPropertyInfo( convertToElementArray, SelectionPattern.SelectionProperty, typeof(AutomationElement[]), new AutomationElement[]{} ), + new AutomationPropertyInfo( convertToElementArray, SelectionPattern.SelectionProperty, typeof(AutomationElement[]), Array.Empty()), new AutomationPropertyInfo( convertToBool, SelectionPattern.CanSelectMultipleProperty, typeof(bool), false ), new AutomationPropertyInfo( convertToBool, SelectionPattern.IsSelectionRequiredProperty, typeof(bool), false ), new AutomationPropertyInfo( null, GridPattern.RowCountProperty, typeof(int), 0 ), @@ -351,7 +351,7 @@ private static object ConvertToAutomationHeadingLevel(object value) new AutomationPropertyInfo( convertToDockPosition, DockPattern.DockPositionProperty, typeof(DockPosition), DockPosition.None ), new AutomationPropertyInfo( convertToExpandCollapseState, ExpandCollapsePattern.ExpandCollapseStateProperty, typeof(ExpandCollapseState), ExpandCollapseState.LeafNode ), new AutomationPropertyInfo( null, MultipleViewPattern.CurrentViewProperty, typeof(int), 0 ), - new AutomationPropertyInfo( null, MultipleViewPattern.SupportedViewsProperty, typeof(int []), new int [0] ), + new AutomationPropertyInfo( null, MultipleViewPattern.SupportedViewsProperty, typeof(int []), Array.Empty() ), new AutomationPropertyInfo( convertToBool, WindowPattern.CanMaximizeProperty, typeof(bool), false ), new AutomationPropertyInfo( convertToBool, WindowPattern.CanMinimizeProperty, typeof(bool), false ), new AutomationPropertyInfo( convertToWindowVisualState, WindowPattern.WindowVisualStateProperty, typeof(WindowVisualState), WindowVisualState.Normal ), @@ -360,11 +360,11 @@ private static object ConvertToAutomationHeadingLevel(object value) new AutomationPropertyInfo( convertToBool, WindowPattern.IsTopmostProperty, typeof(bool), false ), new AutomationPropertyInfo( convertToBool, SelectionItemPattern.IsSelectedProperty, typeof(bool), false ), new AutomationPropertyInfo( convertToElement, SelectionItemPattern.SelectionContainerProperty, typeof(AutomationElement), null ), - new AutomationPropertyInfo( convertToElementArray, TablePattern.RowHeadersProperty, typeof(AutomationElement []), new AutomationElement [0] ), - new AutomationPropertyInfo( convertToElementArray, TablePattern.ColumnHeadersProperty, typeof(AutomationElement []), new AutomationElement [0] ), + new AutomationPropertyInfo( convertToElementArray, TablePattern.RowHeadersProperty, typeof(AutomationElement[]), Array.Empty()), + new AutomationPropertyInfo( convertToElementArray, TablePattern.ColumnHeadersProperty, typeof(AutomationElement[]), Array.Empty()), new AutomationPropertyInfo( convertToRowOrColumnMajor, TablePattern.RowOrColumnMajorProperty, typeof(RowOrColumnMajor), RowOrColumnMajor.Indeterminate ), - new AutomationPropertyInfo( convertToElementArray, TableItemPattern.RowHeaderItemsProperty, typeof(AutomationElement []), new AutomationElement [0] ), - new AutomationPropertyInfo( convertToElementArray, TableItemPattern.ColumnHeaderItemsProperty, typeof(AutomationElement []), new AutomationElement [0] ), + new AutomationPropertyInfo( convertToElementArray, TableItemPattern.RowHeaderItemsProperty, typeof(AutomationElement[]), Array.Empty()), + new AutomationPropertyInfo( convertToElementArray, TableItemPattern.ColumnHeaderItemsProperty, typeof(AutomationElement[]), Array.Empty()), new AutomationPropertyInfo( convertToToggleState, TogglePattern.ToggleStateProperty, typeof(ToggleState), ToggleState.Indeterminate ), new AutomationPropertyInfo( convertToBool, TransformPattern.CanMoveProperty, typeof(bool), false ), new AutomationPropertyInfo( convertToBool, TransformPattern.CanResizeProperty, typeof(bool), false ), diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs index 9e4aa5c7bf2..a5f884a0e1d 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs @@ -450,7 +450,7 @@ internal static UiaCacheResponse[] UiaFind(SafeNodeHandle hnode, UiaFindParams f if (requestedData == null) { Debug.Assert(offsets == null && treeStructures == null, "if nothin found, all out params shoud be null"); - return new UiaCacheResponse[] {}; // Return empty cacheresponse, not null. + return Array.Empty(); // Return empty cacheresponse, not null. } Debug.Assert(offsets.Length == treeStructures.Length); @@ -869,7 +869,7 @@ internal static SafeTextRangeHandle [] TextPattern_GetSelection(SafePatternHandl CheckError(RawTextPattern_GetSelection(hobj, out arr)); if (arr == null) { - return new SafeTextRangeHandle[] { }; + return Array.Empty(); } SafeTextRangeHandle[] result = new SafeTextRangeHandle[arr.Length]; for (int i = 0; i < arr.Length; i++) @@ -885,7 +885,7 @@ internal static SafeTextRangeHandle[] TextPattern_GetVisibleRanges(SafePatternHa CheckError(RawTextPattern_GetVisibleRanges(hobj, out arr)); if (arr == null) { - return new SafeTextRangeHandle[] { }; + return Array.Empty(); } SafeTextRangeHandle[] result = new SafeTextRangeHandle[arr.Length]; for (int i = 0; i < arr.Length; i++) diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs index 56cc1956167..de2e3835f78 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs @@ -407,7 +407,7 @@ internal static UiaCoreApi.UiaCacheRequest DefaultUiaCacheRequest { if(_defaultUiaCacheRequest == null) { - _defaultUiaCacheRequest = new UiaCoreApi.UiaCacheRequest(Automation.ControlViewCondition, TreeScope.Element, new AutomationProperty[] { AutomationElement.RuntimeIdProperty }, new AutomationPattern[] { }, AutomationElementMode.Full); + _defaultUiaCacheRequest = new UiaCoreApi.UiaCacheRequest(Automation.ControlViewCondition, TreeScope.Element, new AutomationProperty[] { AutomationElement.RuntimeIdProperty }, Array.Empty(), AutomationElementMode.Full); } return _defaultUiaCacheRequest; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAANativeProvider.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAANativeProvider.cs index 3f98b0c8a2b..a21dcbed75e 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAANativeProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAANativeProvider.cs @@ -570,7 +570,7 @@ IRawElementProviderSimple[] ISelectionProvider.GetSelection() Accessible[] accessibles = _acc.GetSelection(); if (accessibles == null) - return new IRawElementProviderSimple[] {}; + return Array.Empty(); IRawElementProviderSimple [] rawEPS= new IRawElementProviderSimple[accessibles.Length]; for (int i=0;i(); else return new ITextRangeProvider[] { new WindowsRichEditRange(range, this) }; } @@ -249,7 +249,7 @@ ITextRangeProvider [] ITextProvider.GetVisibleRanges() ITextRange range = GetVisibleRange(); if (range == null) - return new ITextRangeProvider[] { }; + return Array.Empty(); else return new ITextRangeProvider[] { new WindowsRichEditRange(range, this) }; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationTypes/System/Windows/Automation/ControlType.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationTypes/System/Windows/Automation/ControlType.cs index 2d09ab61680..17da12b91ee 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationTypes/System/Windows/Automation/ControlType.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationTypes/System/Windows/Automation/ControlType.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -70,13 +70,13 @@ internal static ControlType Register(AutomationIdentifierConstants.ControlTypes internal static ControlType Register(AutomationIdentifierConstants.ControlTypes id, string programmaticName, string stId, AutomationProperty[] requiredProperties) { - return ControlType.Register(id, programmaticName, stId, requiredProperties, Array.Empty(), new AutomationPattern[0][]); + return ControlType.Register(id, programmaticName, stId, requiredProperties, Array.Empty(), Array.Empty()); } //Required patterns, never supported patterns and required properties are set to an empty array internal static ControlType Register(AutomationIdentifierConstants.ControlTypes id, string programmaticName, string stId) { - return ControlType.Register(id, programmaticName, stId, Array.Empty(), Array.Empty(), new AutomationPattern[0][]); + return ControlType.Register(id, programmaticName, stId, Array.Empty(), Array.Empty(), Array.Empty()); } #endregion @@ -232,7 +232,7 @@ public AutomationProperty[] GetRequiredProperties() }); /// ControlType ID: Document - Lets a user view/manipulate multiple pages of text. - public static readonly ControlType Document = ControlType.Register(AutomationIdentifierConstants.ControlTypes.Document, "ControlType.Document", nameof(SR.LocalizedControlTypeDocument), new AutomationProperty[0], + public static readonly ControlType Document = ControlType.Register(AutomationIdentifierConstants.ControlTypes.Document, "ControlType.Document", nameof(SR.LocalizedControlTypeDocument), Array.Empty(), new AutomationPattern[] { ValuePatternIdentifiers.Pattern }, new AutomationPattern[][] { new AutomationPattern[] { ScrollPatternIdentifiers.Pattern } , From 6fd0c31babc6484d2c6e1c1be9a7d918a4cb56bd Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Sat, 11 Jan 2025 22:18:57 +0100 Subject: [PATCH 2/3] mimic #4027 for XamlMemberInvoker --- .../src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs index a9eb275cf99..7171caf20ea 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -13,7 +13,6 @@ public class XamlMemberInvoker { private static XamlMemberInvoker s_Directive; private static XamlMemberInvoker s_Unknown; - private static object[] s_emptyObjectArray = Array.Empty(); private XamlMember _member; private NullableReference _shouldSerializeMethod; @@ -65,7 +64,7 @@ public virtual object GetValue(object instance) } else { - return UnderlyingGetter.Invoke(instance, s_emptyObjectArray); + return UnderlyingGetter.Invoke(instance, Array.Empty()); } } From 9349586bb69ee063ff896fa1de88baff9f686c9f Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Sat, 11 Jan 2025 22:26:00 +0100 Subject: [PATCH 3/3] Avoid one more unnecessary static pointer holder --- .../MS/Internal/PtsTable/RowSpanVector.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsTable/RowSpanVector.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsTable/RowSpanVector.cs index c4229b27bea..4ccd2b111ed 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsTable/RowSpanVector.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsTable/RowSpanVector.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -156,7 +156,6 @@ internal void GetNextAvailableRange(out int firstAvailableIndex, out int firstOc /// Array of cells. May be empty internal void GetSpanCells(out TableCell[] cells, out bool isLastRowOfAnySpan) { - cells = s_noCells; isLastRowOfAnySpan = false; // iterate the tail of entries (if any) @@ -204,10 +203,13 @@ internal void GetSpanCells(out TableCell[] cells, out bool isLastRowOfAnySpan) _size = j + 1; } - - #if DEBUG + else + { + cells = Array.Empty(); + } +#if DEBUG _index = -1; - #endif // DEBUG +#endif } #endregion Internal Methods @@ -265,8 +267,6 @@ private void InflateCapacity() private int _size; // current size of the list private int _index; // index used for iteration (GetFirst / GetNext) private const int c_defaultCapacity = 8; // default capacity - private static TableCell[] s_noCells = Array.Empty(); // empty array RowSpanVector returns to rows that do not - // have row spanned cells #endregion Private Fields //------------------------------------------------------