コード例 #1
0
ファイル: ObjectPool.cs プロジェクト: sebas77/Svelto.Common
        T ReuseInstance(FasterList <T> pool, Func <T> onFirstInit)
        {
            T obj = null;

            while (IsNull(obj) == true && pool.count > 0)
            {
                obj = pool.Pop();
            }

            if (IsNull(obj) == true)
            {
                obj = onFirstInit();

                _objectsCreated++;
            }
            else
            {
#if DEBUG && !PROFILE_SVELTO
                alreadyRecycled.Remove(obj);
#endif
                _objectsReused++;
            }

            return(obj);
        }
コード例 #2
0
        public void TestInsert()
        {
            FasterList <int> list = new FasterList <int>();

            for (int i = 0; i < 10; i++)
            {
                list.InsertAt(0, i);
            }

            for (int i = 0; i < 10; i++)
            {
                Assert.That(list.Pop(), Is.EqualTo(i));
            }

            Assert.That(list.capacity, Is.EqualTo(10));
            Assert.That(list.count, Is.EqualTo(0));
        }
コード例 #3
0
        public void TestPop()
        {
            FasterList <int> list = new FasterList <int>();

            for (int i = 0; i < 10; i++)
            {
                list.Push(i);
            }

            for (int i = 9; i >= 0; i--)
            {
                Assert.That(list.Pop(), Is.EqualTo(i));
            }

            Assert.That(list.capacity, Is.EqualTo(10));
            Assert.That(list.count, Is.EqualTo(0));
        }