Cysharp / ObservableCollections

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

fix CloneCollection #43

Closed prozolic closed 4 weeks ago

prozolic commented 1 month ago

I think it's the same bug as #38, In some cases, values were not added correctly when executing ObvervableList.AddRange.

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

var list = new ObservableList<int>();
list.AddRange(Range(20));

The cause is that when CloneCollection<T>.TryEnsureCapacity is executed, the items from the old array are not copied to the new array. Therefore, I have modified the old array items to be copied to the new array as well.

neuecc commented 4 weeks ago

thanks!