Skip to content

Commit 78d1f92

Browse files
fix: Use IReadOnlyList for menu items to avoid unnecessary copies
Co-authored-by: MartinZikmund <1075116+MartinZikmund@users.noreply.github.com>
1 parent c72690e commit 78d1f92

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

src/Uno.UI.Runtime.Skia.MacOS/UI/NativeMenu/MacOSNativeMenuBarExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void Register()
2727

2828
public bool IsSupported => true;
2929

30-
public void Apply(IList<NativeMenuItem> items)
30+
public void Apply(IReadOnlyList<NativeMenuItem> items)
3131
{
3232
// Clear existing menus first
3333
NativeMenuInterop.uno_menu_bar_clear();

src/Uno.UWP/UI/NativeMenu/INativeMenuBarExtension.skia.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ internal interface INativeMenuBarExtension
1919
/// Applies the menu items to the native menu bar.
2020
/// </summary>
2121
/// <param name="items">The collection of top-level menu items to apply.</param>
22-
void Apply(IList<NativeMenuItem> items);
22+
void Apply(IReadOnlyList<NativeMenuItem> items);
2323
}
2424
#endif

src/Uno.UWP/UI/NativeMenu/NativeMenuBar.iOS.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ partial void ApplyNativeMenuPartial()
1919
{
2020
// On iOS, menu bar integration requires buildMenu(with:) to be called from the UIApplicationDelegate.
2121
// This implementation stores the menu structure to be used when the system requests menu building.
22-
NativeMenuBridgeiOS.SetMenuItems(_items.ToList());
22+
NativeMenuBridgeiOS.SetMenuItems(_items);
2323
}
2424
}
2525

@@ -28,9 +28,9 @@ partial void ApplyNativeMenuPartial()
2828
/// </summary>
2929
internal static class NativeMenuBridgeiOS
3030
{
31-
private static List<NativeMenuItem>? _menuItems;
31+
private static IReadOnlyList<NativeMenuItem>? _menuItems;
3232

33-
internal static void SetMenuItems(List<NativeMenuItem> items)
33+
internal static void SetMenuItems(IReadOnlyList<NativeMenuItem> items)
3434
{
3535
_menuItems = items;
3636
}
@@ -42,7 +42,7 @@ internal static void SetMenuItems(List<NativeMenuItem> items)
4242
/// <param name="builder">The UIMenuBuilder provided by iOS.</param>
4343
public static void BuildMenu(IUIMenuBuilder builder)
4444
{
45-
if (_menuItems == null || !_menuItems.Any())
45+
if (_menuItems == null || _menuItems.Count == 0)
4646
{
4747
return;
4848
}

src/Uno.UWP/UI/NativeMenu/NativeMenuBar.skia.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#if __SKIA__
22
#nullable enable
33

4-
using System.Linq;
54
using Uno.Foundation.Extensibility;
65

76
namespace Uno.UI.NativeMenu;
@@ -18,7 +17,7 @@ static partial void IsNativeMenuSupportedPartial(ref bool isSupported)
1817

1918
partial void ApplyNativeMenuPartial()
2019
{
21-
GetExtension()?.Apply(_items.ToList());
20+
GetExtension()?.Apply(_items);
2221
}
2322

2423
private static INativeMenuBarExtension? GetExtension()

0 commit comments

Comments
 (0)