Cysharp / ObservableCollections

High performance observable collections and synchronized views, for WPF, Blazor, Unity.
MIT License
602 stars 46 forks source link

fix ResizableArray #51

Closed prozolic closed 3 months ago

prozolic commented 5 months ago

IndexOutOfRangeException was thrown in some cases when executing ObservableHashSet.AddRange.

static IEnumerable<int> Range(int count)
{
    foreach (var i in Enumerable.Range(0, count))
    {
        yield return i;
    }
}

var set = new ObservableHashSet<int>();
set.AddRange(Range(20));

The reason is that when ResizableArray<T>.EnsureCapacity is executed, the capacity of the new array equals the capacity of the old array. Therefore, I modified it to create a new array with twice the capacity of the old one.

neuecc commented 3 months ago

Thank you! This was a terrible bug.