From 15b145d9cc6fba834b3ded831af6c9aa086d9782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Komosi=C5=84ski?= Date: Mon, 12 Jul 2021 12:22:07 +0200 Subject: [PATCH] Merge pull request #6220 from pr8x/expose-Ensure-Capacity Expose EnsureCapacity() on AvaloniaList --- src/Avalonia.Base/Collections/AvaloniaList.cs | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Avalonia.Base/Collections/AvaloniaList.cs b/src/Avalonia.Base/Collections/AvaloniaList.cs index 5681214222..2c7f34c5be 100644 --- a/src/Avalonia.Base/Collections/AvaloniaList.cs +++ b/src/Avalonia.Base/Collections/AvaloniaList.cs @@ -454,6 +454,28 @@ namespace Avalonia.Collections } } + /// + /// Ensures that the capacity of the list is at least . + /// + /// The capacity. + public void EnsureCapacity(int capacity) + { + // Adapted from List implementation. + var currentCapacity = _inner.Capacity; + + if (currentCapacity < capacity) + { + var newCapacity = currentCapacity == 0 ? 4 : currentCapacity * 2; + + if (newCapacity < capacity) + { + newCapacity = capacity; + } + + _inner.Capacity = newCapacity; + } + } + /// /// Removes an item from the collection. /// @@ -633,24 +655,6 @@ namespace Avalonia.Collections /// Delegate[] INotifyCollectionChangedDebug.GetCollectionChangedSubscribers() => _collectionChanged?.GetInvocationList(); - private void EnsureCapacity(int capacity) - { - // Adapted from List implementation. - var currentCapacity = _inner.Capacity; - - if (currentCapacity < capacity) - { - var newCapacity = currentCapacity == 0 ? 4 : currentCapacity * 2; - - if (newCapacity < capacity) - { - newCapacity = capacity; - } - - _inner.Capacity = newCapacity; - } - } - /// /// Raises the event with an add action. ///