internal Enumerator(SparseQueue <T> q) { this._q = q; this._version = this._q._version; this._index = -1; this._currentElement = default(T); }
private static void Clear(Dictionary <TKey, SparseQueue <TValue> > pools, Action <TKey, TValue> disposeValueCallback) { foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair in pools) { SparseQueue <TValue> queue = pair.Value; foreach (TValue local in queue) { disposeValueCallback(pair.Key, local); } queue.Clear(); queue.TrimExcess(); } }
public ObjectPoolTicket <TValue> Get(TKey key) { object sync = this.sync; lock (sync) { SparseQueue <TValue> queue; if (!this.pools.TryGetValue(key, out queue)) { queue = new SparseQueue <TValue>(); this.pools.Add(key, queue); } if (queue.Any <TValue>()) { return(new Ticket <TKey, TValue>((ObjectPool <TKey, TValue>) this, key, queue.Dequeue())); } } return(new Ticket <TKey, TValue>((ObjectPool <TKey, TValue>) this, key, this.valueFactory(key))); }
private void Return(TKey key, TValue value) { object sync = this.sync; lock (sync) { if (this.IsDisposed) { this.disposeValueCallback(key, value); } else { SparseQueue <TValue> queue; if (!this.pools.TryGetValue(key, out queue)) { queue = new SparseQueue <TValue>(); this.pools.Add(key, queue); } queue.Enqueue(value); } } }
public void TrimExcess() { SegmentedList <KeyValuePair <TKey, SparseQueue <TValue> > > list = null; object sync = this.sync; lock (sync) { foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair in this.pools) { SparseQueue <TValue> collection = pair.Value; if (collection.Any <TValue>()) { collection.TrimExcess(); } else { if (list == null) { list = new SegmentedList <KeyValuePair <TKey, SparseQueue <TValue> > >(); } list.Add(pair); } } if (list != null) { foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair2 in list) { this.pools.Remove(pair2.Key); } } } foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair3 in list) { pair3.Value.TrimExcess(); } }
public void Dispose() { this._q = null; this._currentElement = default(T); }