Introduce FirstOrDefault extensions method for Array.Find and List.Find.
This allows the LINQ spelling to be used, but benefits from the performance improvement of the specific methods for these classes that provide the same result.
This commit is contained in:
@@ -283,7 +283,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
public void ScrollToItem(string itemKey, bool smooth = false)
|
||||
{
|
||||
var item = Children.Find(c => c is ScrollItemWidget si && si.ItemKey == itemKey);
|
||||
var item = Children.FirstOrDefault(c => c is ScrollItemWidget si && si.ItemKey == itemKey);
|
||||
|
||||
if (item != null)
|
||||
ScrollToItem(item, smooth);
|
||||
@@ -291,7 +291,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
public void ScrollToSelectedItem()
|
||||
{
|
||||
var item = Children.Find(c => c is ScrollItemWidget si && si.IsSelected());
|
||||
var item = Children.FirstOrDefault(c => c is ScrollItemWidget si && si.IsSelected());
|
||||
|
||||
if (item != null)
|
||||
ScrollToItem(item);
|
||||
@@ -468,7 +468,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (collection != col)
|
||||
return;
|
||||
|
||||
var widget = Children.Find(w => widgetItemEquals(w, item));
|
||||
var widget = Children.FirstOrDefault(w => widgetItemEquals(w, item));
|
||||
if (widget != null)
|
||||
RemoveChild(widget);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user