internal static IBorrowed <ConcurrentQueue <T> > Borrow() { if (Cache.TryDequeue(out var queue)) { return(Borrowed.Create(queue, Return)); } return(Borrowed.Create(new ConcurrentQueue <T>(), Return)); }
internal static IBorrowed <ConcurrentDictionary <TKey, TValue> > Borrow() { if (Cache.TryDequeue(out var dictionary)) { return(Borrowed.Create(dictionary, Return)); } return(Borrowed.Create(new ConcurrentDictionary <TKey, TValue>(), Return)); }
public static IBorrowed <ChildNodes <T> > Borrow() { if (Cache.TryDequeue(out var childNodes)) { return(Borrowed.Create(childNodes, Return)); } return(Borrowed.Create(new ChildNodes <T>(), Return)); }
internal static IBorrowed <List <T> > Borrow() { if (Cache.TryDequeue(out var list)) { return(Borrowed.Create(list, Return)); } return(Borrowed.Create(new List <T>(), Return)); }
internal static IBorrowed <HashSet <T> > Borrow() { if (Pool.TryDequeue(out var set)) { return(Borrowed.Create(set, Return)); } else { return(Borrowed.Create(new HashSet <T>(ReferenceComparer <T> .Default), Return)); } }
internal static IBorrowed <Dictionary <TKey, TValue> > Borrow() { Dictionary <TKey, TValue> dictionary; if (Cache.TryDequeue(out dictionary)) { return(Borrowed.Create(dictionary, Return)); } return(Borrowed.Create(new Dictionary <TKey, TValue>(), Return)); }
internal static IBorrowed <HashSet <T> > Borrow(Func <T, T, bool> compare, Func <T, int> getHashCode) { Debug.Assert(compare != null, "compare == null"); Debug.Assert(getHashCode != null, "getHashCode == null"); if (Cache.TryDequeue(out var set)) { ((WrappingComparer)set.Comparer).Compare = compare; ((WrappingComparer)set.Comparer).HashCode = getHashCode; return(Borrowed.Create(set, Return)); } set = new HashSet <T>(new WrappingComparer { Compare = compare, HashCode = getHashCode }); return(Borrowed.Create(set, Return)); }