fix ResizableArray

This commit is contained in:
prozolic 2024-06-26 22:52:22 +09:00
parent 7e139dc57a
commit 923f8869a5

View File

@ -33,8 +33,10 @@ namespace ObservableCollections.Internal
[MethodImpl(MethodImplOptions.NoInlining)]
void EnsureCapacity()
{
var newArray = array.AsSpan().ToArray();
ArrayPool<T>.Shared.Return(array!, RuntimeHelpersEx.IsReferenceOrContainsReferences<T>());
var oldArray = array!;
var newArray = ArrayPool<T>.Shared.Rent(oldArray.Length * 2);
Array.Copy(oldArray, newArray, oldArray.Length);
ArrayPool<T>.Shared.Return(oldArray, RuntimeHelpersEx.IsReferenceOrContainsReferences<T>());
array = newArray;
}