Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Aug 13, 2024
2 parents 5b20164 + d349335 commit de8cbeb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ObservableCollections/Internal/ResizableArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public void Add(T item)
[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;
}

Expand Down

0 comments on commit de8cbeb

Please sign in to comment.