Skip to content

Commit

Permalink
🐛Registry<T> now prunes null items before returning its list
Browse files Browse the repository at this point in the history
  • Loading branch information
codeimpossible committed Aug 28, 2021
1 parent 82d10dc commit de52c76
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Chonks/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Registry<T> : IRegistry<T> {
public event ItemRegistered<T> OnItemRegistered;

public T[] List() {
Prune();
return _items.ToArray();
}

Expand All @@ -17,6 +18,17 @@ public class Registry<T> : IRegistry<T> {
}
}

private void Prune() {
int idx = 0;
while (idx < _items.Count) {
if (_items[idx] == null) {
_items.RemoveAt(idx);
continue;
}
idx++;
}
}

public void Unregister(T instance) {
_items.Remove(instance);
}
Expand Down

0 comments on commit de52c76

Please sign in to comment.