Browse Source

Used ToArray where it benefits over ToList

pull/7900/head
Yoh Deadfall 5 years ago
parent
commit
55710e8514
  1. 2
      src/Avalonia.Animation/Easing/Easing.cs
  2. 2
      src/Avalonia.Base/Collections/AvaloniaDictionary.cs
  3. 2
      src/Avalonia.Base/Collections/AvaloniaList.cs
  4. 2
      src/Avalonia.Base/Data/Core/PropertyPath.cs
  5. 2
      src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs
  6. 2
      src/Avalonia.Build.Tasks/GenerateAvaloniaResourcesTask.cs
  7. 2
      src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs
  8. 2
      src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs
  9. 4
      src/Avalonia.Controls/AutoCompleteBox.cs
  10. 12
      src/Avalonia.Controls/Generators/ItemContainerGenerator.cs
  11. 2
      src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs
  12. 5
      src/Avalonia.Controls/Primitives/PopupPositioning/ManagedPopupPositionerPopupImplHelper.cs
  13. 10
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
  14. 4
      src/Avalonia.Controls/Selection/InternalSelectionModel.cs
  15. 2
      src/Avalonia.Controls/TreeView.cs
  16. 4
      src/Avalonia.Controls/Utils/CollectionChangedEventManager.cs
  17. 6
      src/Avalonia.Controls/Window.cs
  18. 6
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs
  19. 2
      src/Avalonia.Input/FocusManager.cs
  20. 2
      src/Avalonia.Input/TouchDevice.cs
  21. 2
      src/Avalonia.Visuals/Animation/CompositePageTransition.cs
  22. 2
      src/Avalonia.Visuals/Media/GradientStops.cs
  23. 13
      src/Avalonia.X11/Glx/GlxDisplay.cs
  24. 4
      src/Avalonia.X11/X11Globals.cs
  25. 5
      src/Windows/Avalonia.Win32/TrayIconImpl.cs

2
src/Avalonia.Animation/Easing/Easing.cs

@ -39,7 +39,7 @@ namespace Avalonia.Animation.Easings
var derivedTypes = typeof(Easing).Assembly.GetTypes() var derivedTypes = typeof(Easing).Assembly.GetTypes()
.Where(p => p.Namespace == s_thisType.Namespace) .Where(p => p.Namespace == s_thisType.Namespace)
.Where(p => p.IsSubclassOf(s_thisType)) .Where(p => p.IsSubclassOf(s_thisType))
.Select(p => p).ToList(); .Select(p => p);
foreach (var easingType in derivedTypes) foreach (var easingType in derivedTypes)
_easingTypes.Add(easingType.Name, easingType); _easingTypes.Add(easingType.Name, easingType);

2
src/Avalonia.Base/Collections/AvaloniaDictionary.cs

@ -123,7 +123,7 @@ namespace Avalonia.Collections
{ {
var e = new NotifyCollectionChangedEventArgs( var e = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Remove, NotifyCollectionChangedAction.Remove,
old.ToList(), old.ToArray(),
-1); -1);
CollectionChanged(this, e); CollectionChanged(this, e);
} }

2
src/Avalonia.Base/Collections/AvaloniaList.cs

@ -222,7 +222,7 @@ namespace Avalonia.Collections
{ {
var e = ResetBehavior == ResetBehavior.Reset ? var e = ResetBehavior == ResetBehavior.Reset ?
EventArgsCache.ResetCollectionChanged : EventArgsCache.ResetCollectionChanged :
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, _inner.ToList(), 0); new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, _inner.ToArray(), 0);
_inner.Clear(); _inner.Clear();

2
src/Avalonia.Base/Data/Core/PropertyPath.cs

@ -10,7 +10,7 @@ namespace Avalonia.Data.Core
public PropertyPath(IEnumerable<IPropertyPathElement> elements) public PropertyPath(IEnumerable<IPropertyPathElement> elements)
{ {
Elements = elements.ToList(); Elements = elements.ToArray();
} }
} }

2
src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs

@ -23,7 +23,7 @@ namespace Avalonia.Utilities
var assetDoc = XDocument.Load(stream); var assetDoc = XDocument.Load(stream);
XNamespace assetNs = assetDoc.Root!.Attribute("xmlns")!.Value; XNamespace assetNs = assetDoc.Root!.Attribute("xmlns")!.Value;
List<AvaloniaResourcesIndexEntry> entries= List<AvaloniaResourcesIndexEntry> entries =
(from entry in assetDoc.Root.Element(assetNs + "Entries")!.Elements(assetNs + "AvaloniaResourcesIndexEntry") (from entry in assetDoc.Root.Element(assetNs + "Entries")!.Elements(assetNs + "AvaloniaResourcesIndexEntry")
select new AvaloniaResourcesIndexEntry select new AvaloniaResourcesIndexEntry
{ {

2
src/Avalonia.Build.Tasks/GenerateAvaloniaResourcesTask.cs

@ -105,7 +105,7 @@ namespace Avalonia.Build.Tasks
{ {
var typeToXamlIndex = new Dictionary<string, string>(); var typeToXamlIndex = new Dictionary<string, string>();
foreach (var s in sources.ToList()) foreach (var s in sources.ToArray())
{ {
if (s.Path.ToLowerInvariant().EndsWith(".xaml") || s.Path.ToLowerInvariant().EndsWith(".paml") || s.Path.ToLowerInvariant().EndsWith(".axaml")) if (s.Path.ToLowerInvariant().EndsWith(".xaml") || s.Path.ToLowerInvariant().EndsWith(".paml") || s.Path.ToLowerInvariant().EndsWith(".axaml"))
{ {

2
src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs

@ -3946,7 +3946,7 @@ namespace Avalonia.Collections
{ {
sort.Initialize(itemType); sort.Initialize(itemType);
if(seq is IOrderedEnumerable<object> orderedEnum) if (seq is IOrderedEnumerable<object> orderedEnum)
{ {
seq = sort.ThenBy(orderedEnum); seq = sort.ThenBy(orderedEnum);
} }

2
src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs

@ -65,7 +65,7 @@ namespace Avalonia.Controls.ApplicationLifetimes
/// <inheritdoc/> /// <inheritdoc/>
public Window? MainWindow { get; set; } public Window? MainWindow { get; set; }
public IReadOnlyList<Window> Windows => _windows.ToList(); public IReadOnlyList<Window> Windows => _windows.ToArray();
private void HandleWindowClosed(Window window) private void HandleWindowClosed(Window window)
{ {

4
src/Avalonia.Controls/AutoCompleteBox.cs

@ -2180,7 +2180,7 @@ namespace Avalonia.Controls
} }
// Store a local cached copy of the data // Store a local cached copy of the data
_items = newValue == null ? null : new List<object>(newValue.Cast<object>().ToList()); _items = newValue == null ? null : new List<object>(newValue.Cast<object>());
// Clear and set the view on the selection adapter // Clear and set the view on the selection adapter
ClearView(); ClearView();
@ -2239,7 +2239,7 @@ namespace Avalonia.Controls
ClearView(); ClearView();
if (Items != null) if (Items != null)
{ {
_items = new List<object>(Items.Cast<object>().ToList()); _items = new List<object>(Items.Cast<object>());
} }
} }

12
src/Avalonia.Controls/Generators/ItemContainerGenerator.cs

@ -82,7 +82,7 @@ namespace Avalonia.Controls.Generators
{ {
var toMove = _containers.Where(x => x.Key >= index) var toMove = _containers.Where(x => x.Key >= index)
.OrderByDescending(x => x.Key) .OrderByDescending(x => x.Key)
.ToList(); .ToArray();
foreach (var i in toMove) foreach (var i in toMove)
{ {
@ -111,7 +111,7 @@ namespace Avalonia.Controls.Generators
} }
var toMove = _containers.Where(x => x.Key >= startingIndex) var toMove = _containers.Where(x => x.Key >= startingIndex)
.OrderBy(x => x.Key).ToList(); .OrderBy(x => x.Key).ToArray();
foreach (var i in toMove) foreach (var i in toMove)
{ {
@ -122,9 +122,9 @@ namespace Avalonia.Controls.Generators
Dematerialized?.Invoke(this, new ItemContainerEventArgs(startingIndex, result)); Dematerialized?.Invoke(this, new ItemContainerEventArgs(startingIndex, result));
if (toMove.Count > 0) if (toMove.Length > 0)
{ {
var containers = toMove.Select(x => x.Value).ToList(); var containers = toMove.Select(x => x.Value).ToArray();
Recycled?.Invoke(this, new ItemContainerEventArgs(containers[0].Index, containers)); Recycled?.Invoke(this, new ItemContainerEventArgs(containers[0].Index, containers));
} }
} }
@ -138,10 +138,10 @@ namespace Avalonia.Controls.Generators
/// <inheritdoc/> /// <inheritdoc/>
public virtual IEnumerable<ItemContainerInfo> Clear() public virtual IEnumerable<ItemContainerInfo> Clear()
{ {
var result = Containers.ToList(); var result = Containers.ToArray();
_containers.Clear(); _containers.Clear();
if (result.Count > 0) if (result.Length > 0)
{ {
Dematerialized?.Invoke(this, new ItemContainerEventArgs(0, result)); Dematerialized?.Invoke(this, new ItemContainerEventArgs(0, result));
} }

2
src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs

@ -1051,7 +1051,7 @@ namespace Avalonia.Controls
var currentValueTextSpecialCharacters = currentValueText.Where(c => !char.IsDigit(c)); var currentValueTextSpecialCharacters = currentValueText.Where(c => !char.IsDigit(c));
var textSpecialCharacters = text.Where(c => !char.IsDigit(c)); var textSpecialCharacters = text.Where(c => !char.IsDigit(c));
// same non-digit characters on currentValueText and new text => remove them on new Text to parse it again. // same non-digit characters on currentValueText and new text => remove them on new Text to parse it again.
if (currentValueTextSpecialCharacters.Except(textSpecialCharacters).ToList().Count == 0) if (!currentValueTextSpecialCharacters.Except(textSpecialCharacters).Any())
{ {
foreach (var character in textSpecialCharacters) foreach (var character in textSpecialCharacters)
{ {

5
src/Avalonia.Controls/Primitives/PopupPositioning/ManagedPopupPositionerPopupImplHelper.cs

@ -23,8 +23,9 @@ namespace Avalonia.Controls.Primitives.PopupPositioning
public IReadOnlyList<ManagedPopupPositionerScreenInfo> Screens => public IReadOnlyList<ManagedPopupPositionerScreenInfo> Screens =>
_parent.Screen.AllScreens.Select(s => new ManagedPopupPositionerScreenInfo( _parent.Screen.AllScreens
s.Bounds.ToRect(1), s.WorkingArea.ToRect(1))).ToList(); .Select(s => new ManagedPopupPositionerScreenInfo(s.Bounds.ToRect(1), s.WorkingArea.ToRect(1)))
.ToArray();
public Rect ParentClientAreaScreenGeometry public Rect ParentClientAreaScreenGeometry
{ {

10
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -292,11 +292,11 @@ namespace Avalonia.Controls.Primitives
"collection is different to the Items on the control."); "collection is different to the Items on the control.");
} }
var oldSelection = _selection?.SelectedItems.ToList(); var oldSelection = _selection?.SelectedItems.ToArray();
DeinitializeSelectionModel(_selection); DeinitializeSelectionModel(_selection);
_selection = value; _selection = value;
if (oldSelection?.Count > 0) if (oldSelection?.Length > 0)
{ {
RaiseEvent(new SelectionChangedEventArgs( RaiseEvent(new SelectionChangedEventArgs(
SelectionChangedEvent, SelectionChangedEvent,
@ -845,8 +845,8 @@ namespace Avalonia.Controls.Primitives
{ {
var ev = new SelectionChangedEventArgs( var ev = new SelectionChangedEventArgs(
SelectionChangedEvent, SelectionChangedEvent,
e.DeselectedItems.ToList(), e.DeselectedItems.ToArray(),
e.SelectedItems.ToList()); e.SelectedItems.ToArray());
RaiseEvent(ev); RaiseEvent(ev);
} }
} }
@ -988,7 +988,7 @@ namespace Avalonia.Controls.Primitives
RaiseEvent(new SelectionChangedEventArgs( RaiseEvent(new SelectionChangedEventArgs(
SelectionChangedEvent, SelectionChangedEvent,
Array.Empty<object>(), Array.Empty<object>(),
Selection.SelectedItems.ToList())); Selection.SelectedItems.ToArray()));
} }
} }

4
src/Avalonia.Controls/Selection/InternalSelectionModel.cs

@ -182,8 +182,8 @@ namespace Avalonia.Controls.Selection
try try
{ {
var items = WritableSelectedItems; var items = WritableSelectedItems;
var deselected = e.DeselectedItems.ToList(); var deselected = e.DeselectedItems.ToArray();
var selected = e.SelectedItems.ToList(); var selected = e.SelectedItems.ToArray();
_ignoreSelectedItemsChanges = true; _ignoreSelectedItemsChanges = true;

2
src/Avalonia.Controls/TreeView.cs

@ -849,7 +849,7 @@ namespace Avalonia.Controls
/// <param name="desired">The desired items.</param> /// <param name="desired">The desired items.</param>
private static void SynchronizeItems(IList items, IEnumerable<object> desired) private static void SynchronizeItems(IList items, IEnumerable<object> desired)
{ {
var list = items.Cast<object>().ToList(); var list = items.Cast<object>();
var toRemove = list.Except(desired).ToList(); var toRemove = list.Except(desired).ToList();
var toAdd = desired.Except(list).ToList(); var toAdd = desired.Except(list).ToList();

4
src/Avalonia.Controls/Utils/CollectionChangedEventManager.cs

@ -105,7 +105,7 @@ namespace Avalonia.Controls.Utils
static void Notify( static void Notify(
INotifyCollectionChanged incc, INotifyCollectionChanged incc,
NotifyCollectionChangedEventArgs args, NotifyCollectionChangedEventArgs args,
List<WeakReference<ICollectionChangedListener>> listeners) WeakReference<ICollectionChangedListener>[] listeners)
{ {
foreach (var l in listeners) foreach (var l in listeners)
{ {
@ -132,7 +132,7 @@ namespace Avalonia.Controls.Utils
} }
} }
var l = Listeners.ToList(); var l = Listeners.ToArray();
if (Dispatcher.UIThread.CheckAccess()) if (Dispatcher.UIThread.CheckAccess())
{ {

6
src/Avalonia.Controls/Window.cs

@ -258,7 +258,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets a collection of child windows owned by this window. /// Gets a collection of child windows owned by this window.
/// </summary> /// </summary>
public IReadOnlyList<Window> OwnedWindows => _children.Select(x => x.child).ToList(); public IReadOnlyList<Window> OwnedWindows => _children.Select(x => x.child).ToArray();
/// <summary> /// <summary>
/// Gets or sets a value indicating how the window will size itself to fit its content. /// Gets or sets a value indicating how the window will size itself to fit its content.
@ -527,7 +527,7 @@ namespace Avalonia.Controls
private void CloseInternal() private void CloseInternal()
{ {
foreach (var (child, _) in _children.ToList()) foreach (var (child, _) in _children.ToArray())
{ {
child.CloseInternal(); child.CloseInternal();
} }
@ -551,7 +551,7 @@ namespace Avalonia.Controls
bool canClose = true; bool canClose = true;
foreach (var (child, _) in _children.ToList()) foreach (var (child, _) in _children.ToArray())
{ {
if (child.ShouldCancelClose(args)) if (child.ShouldCancelClose(args))
{ {

6
src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs

@ -18,7 +18,7 @@ namespace Avalonia.Diagnostics.ViewModels
internal class ControlDetailsViewModel : ViewModelBase, IDisposable internal class ControlDetailsViewModel : ViewModelBase, IDisposable
{ {
private readonly IAvaloniaObject _avaloniaObject; private readonly IAvaloniaObject _avaloniaObject;
private IDictionary<object, List<PropertyViewModel>>? _propertyIndex; private IDictionary<object, PropertyViewModel[]>? _propertyIndex;
private PropertyViewModel? _selectedProperty; private PropertyViewModel? _selectedProperty;
private DataGridCollectionView? _propertiesView; private DataGridCollectionView? _propertiesView;
private bool _snapshotStyles; private bool _snapshotStyles;
@ -472,9 +472,9 @@ namespace Avalonia.Diagnostics.ViewModels
.Concat(GetClrProperties(o, _showImplementedInterfaces)) .Concat(GetClrProperties(o, _showImplementedInterfaces))
.OrderBy(x => x, PropertyComparer.Instance) .OrderBy(x => x, PropertyComparer.Instance)
.ThenBy(x => x.Name) .ThenBy(x => x.Name)
.ToList(); .ToArray();
_propertyIndex = properties.GroupBy(x => x.Key).ToDictionary(x => x.Key, x => x.ToList()); _propertyIndex = properties.GroupBy(x => x.Key).ToDictionary(x => x.Key, x => x.ToArray());
var view = new DataGridCollectionView(properties); var view = new DataGridCollectionView(properties);
view.GroupDescriptions.Add(new DataGridPathGroupDescription(nameof(AvaloniaPropertyViewModel.Group))); view.GroupDescriptions.Add(new DataGridPathGroupDescription(nameof(AvaloniaPropertyViewModel.Group)));

2
src/Avalonia.Input/FocusManager.cs

@ -73,7 +73,7 @@ namespace Avalonia.Input
else if (Current != null) else if (Current != null)
{ {
// If control is null, set focus to the topmost focus scope. // If control is null, set focus to the topmost focus scope.
foreach (var scope in GetFocusScopeAncestors(Current).Reverse().ToList()) foreach (var scope in GetFocusScopeAncestors(Current).Reverse().ToArray())
{ {
if (scope != Scope && if (scope != Scope &&
_focusScopes.TryGetValue(scope, out var element) && _focusScopes.TryGetValue(scope, out var element) &&

2
src/Avalonia.Input/TouchDevice.cs

@ -114,7 +114,7 @@ namespace Avalonia.Input
{ {
if (_disposed) if (_disposed)
return; return;
var values = _pointers.Values.ToList(); var values = _pointers.Values.ToArray();
_pointers.Clear(); _pointers.Clear();
_disposed = true; _disposed = true;
foreach (var p in values) foreach (var p in values)

2
src/Avalonia.Visuals/Animation/CompositePageTransition.cs

@ -41,7 +41,7 @@ namespace Avalonia.Animation
{ {
var transitionTasks = PageTransitions var transitionTasks = PageTransitions
.Select(transition => transition.Start(from, to, forward, cancellationToken)) .Select(transition => transition.Start(from, to, forward, cancellationToken))
.ToList(); .ToArray();
return Task.WhenAll(transitionTasks); return Task.WhenAll(transitionTasks);
} }
} }

2
src/Avalonia.Visuals/Media/GradientStops.cs

@ -17,7 +17,7 @@ namespace Avalonia.Media
public IReadOnlyList<ImmutableGradientStop> ToImmutable() public IReadOnlyList<ImmutableGradientStop> ToImmutable()
{ {
return this.Select(x => new ImmutableGradientStop(x.Offset, x.Color)).ToList(); return this.Select(x => new ImmutableGradientStop(x.Offset, x.Color)).ToArray();
} }
} }
} }

13
src/Avalonia.X11/Glx/GlxDisplay.cs

@ -9,7 +9,7 @@ namespace Avalonia.X11.Glx
unsafe class GlxDisplay unsafe class GlxDisplay
{ {
private readonly X11Info _x11; private readonly X11Info _x11;
private readonly List<GlVersion> _probeProfiles; private readonly GlVersion[] _probeProfiles;
private readonly IntPtr _fbconfig; private readonly IntPtr _fbconfig;
private readonly XVisualInfo* _visual; private readonly XVisualInfo* _visual;
private string[] _displayExtensions; private string[] _displayExtensions;
@ -21,7 +21,7 @@ namespace Avalonia.X11.Glx
public GlxDisplay(X11Info x11, IList<GlVersion> probeProfiles) public GlxDisplay(X11Info x11, IList<GlVersion> probeProfiles)
{ {
_x11 = x11; _x11 = x11;
_probeProfiles = probeProfiles.ToList(); _probeProfiles = probeProfiles.ToArray();
_displayExtensions = Glx.GetExtensions(_x11.Display); _displayExtensions = Glx.GetExtensions(_x11.Display);
var baseAttribs = new[] var baseAttribs = new[]
@ -76,10 +76,10 @@ namespace Avalonia.X11.Glx
if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0) if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0)
stencilSize = stencil; stencilSize = stencil;
var pbuffers = Enumerable.Range(0, 2).Select(_ => Glx.CreatePbuffer(_x11.Display, _fbconfig, new[] var attributes = new[] { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
{
GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes);
})).ToList(); Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes);
XLib.XFlush(_x11.Display); XLib.XFlush(_x11.Display);
@ -104,7 +104,6 @@ namespace Avalonia.X11.Glx
$"Renderer '{glInterface.Renderer}' is blacklisted by '{item}'"); $"Renderer '{glInterface.Renderer}' is blacklisted by '{item}'");
} }
} }
} }
IntPtr CreatePBuffer() IntPtr CreatePBuffer()

4
src/Avalonia.X11/X11Globals.cs

@ -41,7 +41,7 @@ namespace Avalonia.X11
{ {
_wmName = value; _wmName = value;
// The collection might change during enumeration // The collection might change during enumeration
foreach (var s in _subscribers.ToList()) foreach (var s in _subscribers.ToArray())
s.WmChanged(value); s.WmChanged(value);
} }
} }
@ -69,7 +69,7 @@ namespace Avalonia.X11
{ {
_isCompositionEnabled = value; _isCompositionEnabled = value;
// The collection might change during enumeration // The collection might change during enumeration
foreach (var s in _subscribers.ToList()) foreach (var s in _subscribers.ToArray())
s.CompositionChanged(value); s.CompositionChanged(value);
} }
} }

5
src/Windows/Avalonia.Win32/TrayIconImpl.cs

@ -217,8 +217,9 @@ namespace Avalonia.Win32
} }
public IReadOnlyList<ManagedPopupPositionerScreenInfo> Screens => public IReadOnlyList<ManagedPopupPositionerScreenInfo> Screens =>
_hiddenWindow.Screens.All.Select(s => new ManagedPopupPositionerScreenInfo( _hiddenWindow.Screens.All
s.Bounds.ToRect(1), s.Bounds.ToRect(1))).ToList(); .Select(s => new ManagedPopupPositionerScreenInfo(s.Bounds.ToRect(1), s.Bounds.ToRect(1)))
.ToArray();
public Rect ParentClientAreaScreenGeometry public Rect ParentClientAreaScreenGeometry
{ {

Loading…
Cancel
Save