diff --git a/osu.Framework.Benchmarks/BenchmarkBindableList.cs b/osu.Framework.Benchmarks/BenchmarkBindableList.cs index fb0d9650c6..9cb5cb6f6a 100644 --- a/osu.Framework.Benchmarks/BenchmarkBindableList.cs +++ b/osu.Framework.Benchmarks/BenchmarkBindableList.cs @@ -19,13 +19,6 @@ public void GlobalSetup() list.Add(i); } - [Benchmark] - public void Add() - { - for (int i = 0; i < 10; i++) - list.Add(i); - } - [Benchmark] public int Enumerate() { diff --git a/osu.Framework/Bindables/BindableList.cs b/osu.Framework/Bindables/BindableList.cs index 7483b18596..2877cf2527 100644 --- a/osu.Framework/Bindables/BindableList.cs +++ b/osu.Framework/Bindables/BindableList.cs @@ -57,7 +57,7 @@ public BindableList(IEnumerable items = null) public T this[int index] { get => collection[index]; - set => setIndex(index, value, getRecursionList()); + set => setIndex(index, value, new HashSet>()); } private void setIndex(int index, T item, HashSet> appliedInstances) @@ -85,7 +85,7 @@ private void setIndex(int index, T item, HashSet> appliedInstanc /// The item to be added. /// Thrown when this is . public void Add(T item) - => add(item, getRecursionList()); + => add(item, new HashSet>()); private void add(T item, HashSet> appliedInstances) { @@ -118,7 +118,7 @@ private void add(T item, HashSet> appliedInstances) /// The item to insert. /// Thrown when this is . public void Insert(int index, T item) - => insert(index, item, getRecursionList()); + => insert(index, item, new HashSet>()); private void insert(int index, T item, HashSet> appliedInstances) { @@ -142,7 +142,7 @@ private void insert(int index, T item, HashSet> appliedInstances /// /// Thrown when this is . public void Clear() - => clear(getRecursionList()); + => clear(new HashSet>()); private void clear(HashSet> appliedInstances) { @@ -182,7 +182,7 @@ public bool Contains(T item) /// true if the removal was successful. /// Thrown if this is . public bool Remove(T item) - => remove(item, getRecursionList()); + => remove(item, new HashSet>()); private bool remove(T item, HashSet> appliedInstances) { @@ -224,7 +224,7 @@ private bool remove(T item, HashSet> appliedInstances) /// The count of items to be removed. public void RemoveRange(int index, int count) { - removeRange(index, count, getRecursionList()); + removeRange(index, count, new HashSet>()); } private void removeRange(int index, int count, HashSet> appliedInstances) @@ -259,7 +259,7 @@ private void removeRange(int index, int count, HashSet> appliedI /// The index of the item to remove. /// Thrown if this is . public void RemoveAt(int index) - => removeAt(index, getRecursionList()); + => removeAt(index, new HashSet>()); private void removeAt(int index, HashSet> appliedInstances) { @@ -285,7 +285,7 @@ private void removeAt(int index, HashSet> appliedInstances) /// /// The predicate. public int RemoveAll(Predicate match) - => removeAll(match, getRecursionList()); + => removeAll(match, new HashSet>()); private int removeAll(Predicate match, HashSet> appliedInstances) { @@ -319,7 +319,7 @@ private int removeAll(Predicate match, HashSet> appliedInstan /// The count of items to be removed. /// The items to replace the removed items with. public void ReplaceRange(int index, int count, IEnumerable newItems) - => replaceRange(index, count, newItems as IList ?? newItems.ToArray(), getRecursionList()); + => replaceRange(index, count, newItems as IList ?? newItems.ToArray(), new HashSet>()); private void replaceRange(int index, int count, IList newItems, HashSet> appliedInstances) { @@ -542,7 +542,7 @@ public virtual void UnbindFrom(IUnbindable them) /// The collection whose items should be added to this collection. /// Thrown if this collection is public void AddRange(IEnumerable items) - => addRange(items as IList ?? items.ToArray(), getRecursionList()); + => addRange(items as IList ?? items.ToArray(), new HashSet>()); private void addRange(IList items, HashSet> appliedInstances) { @@ -567,7 +567,7 @@ private void addRange(IList items, HashSet> appliedInstances) /// The index of the item to move. /// The index specifying the new location of the item. public void Move(int oldIndex, int newIndex) - => move(oldIndex, newIndex, getRecursionList()); + => move(oldIndex, newIndex, new HashSet>()); private void move(int oldIndex, int newIndex, HashSet> appliedInstances) { @@ -691,15 +691,5 @@ private void ensureMutationAllowed() public bool IsDefault => Count == 0; string IFormattable.ToString(string format, IFormatProvider formatProvider) => ((FormattableString)$"{GetType().ReadableName()}({nameof(Count)}={Count})").ToString(formatProvider); - - [ThreadStatic] - private static HashSet> recursionList; - - private static HashSet> getRecursionList() - { - recursionList ??= new HashSet>(); - recursionList.Clear(); - return recursionList; - } } }