Merge pull request #51 from prozolic/pullreq

fix ResizableArray
This commit is contained in:
Yoshifumi Kawai 2024-08-13 20:38:32 +09:00 committed by GitHub
commit d3493356fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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;
}