Exemplo n.º 1
0
        internal static IBorrowed <ConcurrentQueue <T> > Borrow()
        {
            if (Cache.TryDequeue(out var queue))
            {
                return(Borrowed.Create(queue, Return));
            }

            return(Borrowed.Create(new ConcurrentQueue <T>(), Return));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public static IBorrowed <ChildNodes <T> > Borrow()
        {
            if (Cache.TryDequeue(out var childNodes))
            {
                return(Borrowed.Create(childNodes, Return));
            }

            return(Borrowed.Create(new ChildNodes <T>(), Return));
        }
Exemplo n.º 4
0
        internal static IBorrowed <List <T> > Borrow()
        {
            if (Cache.TryDequeue(out var list))
            {
                return(Borrowed.Create(list, Return));
            }

            return(Borrowed.Create(new List <T>(), Return));
        }
Exemplo n.º 5
0
 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));
     }
 }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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));
        }