diff --git a/Shared/ProfilingList.cs b/Shared/ProfilingList.cs index 0e00723..554df89 100644 --- a/Shared/ProfilingList.cs +++ b/Shared/ProfilingList.cs @@ -1,13 +1,14 @@ using System.Collections; using System.Collections.Generic; +using System.Diagnostics; namespace SemiColinGames { // An IList, backed by a List, that prints out a debug message any time that the Capacity // of the underlying List changes. public class ProfilingList : IList { - private List items; + private readonly List items; + private readonly string name; private int previousCapacity; - private string name; public ProfilingList(int capacity, string name) { items = new List(capacity); @@ -15,26 +16,28 @@ namespace SemiColinGames { this.name = name; } + public bool IsReadOnly { + get { return false; } + } + public void Add(T item) { items.Add(item); - if (items.Capacity != previousCapacity) { - Debug.WriteLine($"{name} capacity: {previousCapacity} -> {items.Capacity}"); - previousCapacity = items.Capacity; - } + CheckCapacity(); } public void Insert(int index, T item) { items.Insert(index, item); + CheckCapacity(); + } + + [Conditional("DEBUG")] + private void CheckCapacity() { if (items.Capacity != previousCapacity) { Debug.WriteLine($"{name} capacity: {previousCapacity} -> {items.Capacity}"); previousCapacity = items.Capacity; } } - public bool IsReadOnly { - get { return false; } - } - // Everything below this point is boilerplate delegation to the underlying list. public void Clear() {