Exemplo n.º 1
0
        public static List <T> Rent()
        {
            if (FreeLists.Count == 0)
            {
                return(new List <T>());
            }

            var lastListIndex = FreeLists.Count - 1;
            var lastList      = FreeLists[lastListIndex];

            FreeLists.RemoveAt(lastListIndex);
            FreeListsSet.Remove(lastList);
            lastList.Clear();
            return(lastList);
        }
Exemplo n.º 2
0
        public static void Return([NotNull] List <T> list)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            list.Clear();
            if (FreeListsSet.Contains(list))
            {
                return;
            }

            FreeLists.Add(list);
            FreeListsSet.Add(list);
        }