Skip to content

Commit 7bb0e9e

Browse files
authored
Merge pull request #6356 from smoogipoo/revert-bindablelist-hashset
Revert BindableList GC reduction change
2 parents 55b2291 + 7a3d4bd commit 7bb0e9e

2 files changed

Lines changed: 11 additions & 28 deletions

File tree

osu.Framework.Benchmarks/BenchmarkBindableList.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ public void GlobalSetup()
1919
list.Add(i);
2020
}
2121

22-
[Benchmark]
23-
public void Add()
24-
{
25-
for (int i = 0; i < 10; i++)
26-
list.Add(i);
27-
}
28-
2922
[Benchmark]
3023
public int Enumerate()
3124
{

osu.Framework/Bindables/BindableList.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public BindableList(IEnumerable<T> items = null)
5757
public T this[int index]
5858
{
5959
get => collection[index];
60-
set => setIndex(index, value, getRecursionList());
60+
set => setIndex(index, value, new HashSet<BindableList<T>>());
6161
}
6262

6363
private void setIndex(int index, T item, HashSet<BindableList<T>> appliedInstances)
@@ -85,7 +85,7 @@ private void setIndex(int index, T item, HashSet<BindableList<T>> appliedInstanc
8585
/// <param name="item">The item to be added.</param>
8686
/// <exception cref="InvalidOperationException">Thrown when this <see cref="BindableList{T}"/> is <see cref="Disabled"/>.</exception>
8787
public void Add(T item)
88-
=> add(item, getRecursionList());
88+
=> add(item, new HashSet<BindableList<T>>());
8989

9090
private void add(T item, HashSet<BindableList<T>> appliedInstances)
9191
{
@@ -118,7 +118,7 @@ private void add(T item, HashSet<BindableList<T>> appliedInstances)
118118
/// <param name="item">The item to insert.</param>
119119
/// <exception cref="InvalidOperationException">Thrown when this <see cref="BindableList{T}"/> is <see cref="Disabled"/>.</exception>
120120
public void Insert(int index, T item)
121-
=> insert(index, item, getRecursionList());
121+
=> insert(index, item, new HashSet<BindableList<T>>());
122122

123123
private void insert(int index, T item, HashSet<BindableList<T>> appliedInstances)
124124
{
@@ -142,7 +142,7 @@ private void insert(int index, T item, HashSet<BindableList<T>> appliedInstances
142142
/// </summary>
143143
/// <exception cref="InvalidOperationException">Thrown when this <see cref="BindableList{T}"/> is <see cref="Disabled"/>.</exception>
144144
public void Clear()
145-
=> clear(getRecursionList());
145+
=> clear(new HashSet<BindableList<T>>());
146146

147147
private void clear(HashSet<BindableList<T>> appliedInstances)
148148
{
@@ -182,7 +182,7 @@ public bool Contains(T item)
182182
/// <returns><code>true</code> if the removal was successful.</returns>
183183
/// <exception cref="InvalidOperationException">Thrown if this <see cref="BindableList{T}"/> is <see cref="Disabled"/>.</exception>
184184
public bool Remove(T item)
185-
=> remove(item, getRecursionList());
185+
=> remove(item, new HashSet<BindableList<T>>());
186186

187187
private bool remove(T item, HashSet<BindableList<T>> appliedInstances)
188188
{
@@ -224,7 +224,7 @@ private bool remove(T item, HashSet<BindableList<T>> appliedInstances)
224224
/// <param name="count">The count of items to be removed.</param>
225225
public void RemoveRange(int index, int count)
226226
{
227-
removeRange(index, count, getRecursionList());
227+
removeRange(index, count, new HashSet<BindableList<T>>());
228228
}
229229

230230
private void removeRange(int index, int count, HashSet<BindableList<T>> appliedInstances)
@@ -259,7 +259,7 @@ private void removeRange(int index, int count, HashSet<BindableList<T>> appliedI
259259
/// <param name="index">The index of the item to remove.</param>
260260
/// <exception cref="InvalidOperationException">Thrown if this <see cref="BindableList{T}"/> is <see cref="Disabled"/>.</exception>
261261
public void RemoveAt(int index)
262-
=> removeAt(index, getRecursionList());
262+
=> removeAt(index, new HashSet<BindableList<T>>());
263263

264264
private void removeAt(int index, HashSet<BindableList<T>> appliedInstances)
265265
{
@@ -285,7 +285,7 @@ private void removeAt(int index, HashSet<BindableList<T>> appliedInstances)
285285
/// </summary>
286286
/// <param name="match">The predicate.</param>
287287
public int RemoveAll(Predicate<T> match)
288-
=> removeAll(match, getRecursionList());
288+
=> removeAll(match, new HashSet<BindableList<T>>());
289289

290290
private int removeAll(Predicate<T> match, HashSet<BindableList<T>> appliedInstances)
291291
{
@@ -319,7 +319,7 @@ private int removeAll(Predicate<T> match, HashSet<BindableList<T>> appliedInstan
319319
/// <param name="count">The count of items to be removed.</param>
320320
/// <param name="newItems">The items to replace the removed items with.</param>
321321
public void ReplaceRange(int index, int count, IEnumerable<T> newItems)
322-
=> replaceRange(index, count, newItems as IList ?? newItems.ToArray(), getRecursionList());
322+
=> replaceRange(index, count, newItems as IList ?? newItems.ToArray(), new HashSet<BindableList<T>>());
323323

324324
private void replaceRange(int index, int count, IList newItems, HashSet<BindableList<T>> appliedInstances)
325325
{
@@ -542,7 +542,7 @@ public virtual void UnbindFrom(IUnbindable them)
542542
/// <param name="items">The collection whose items should be added to this collection.</param>
543543
/// <exception cref="InvalidOperationException">Thrown if this collection is <see cref="Disabled"/></exception>
544544
public void AddRange(IEnumerable<T> items)
545-
=> addRange(items as IList ?? items.ToArray(), getRecursionList());
545+
=> addRange(items as IList ?? items.ToArray(), new HashSet<BindableList<T>>());
546546

547547
private void addRange(IList items, HashSet<BindableList<T>> appliedInstances)
548548
{
@@ -567,7 +567,7 @@ private void addRange(IList items, HashSet<BindableList<T>> appliedInstances)
567567
/// <param name="oldIndex">The index of the item to move.</param>
568568
/// <param name="newIndex">The index specifying the new location of the item.</param>
569569
public void Move(int oldIndex, int newIndex)
570-
=> move(oldIndex, newIndex, getRecursionList());
570+
=> move(oldIndex, newIndex, new HashSet<BindableList<T>>());
571571

572572
private void move(int oldIndex, int newIndex, HashSet<BindableList<T>> appliedInstances)
573573
{
@@ -691,15 +691,5 @@ private void ensureMutationAllowed()
691691
public bool IsDefault => Count == 0;
692692

693693
string IFormattable.ToString(string format, IFormatProvider formatProvider) => ((FormattableString)$"{GetType().ReadableName()}({nameof(Count)}={Count})").ToString(formatProvider);
694-
695-
[ThreadStatic]
696-
private static HashSet<BindableList<T>> recursionList;
697-
698-
private static HashSet<BindableList<T>> getRecursionList()
699-
{
700-
recursionList ??= new HashSet<BindableList<T>>();
701-
recursionList.Clear();
702-
return recursionList;
703-
}
704694
}
705695
}

0 commit comments

Comments
 (0)