コード例 #1
0
        public void Test_StringPool_Add_Single()
        {
            var pool = new StringPool();

            string hello = nameof(hello);

            Assert.IsFalse(pool.TryGet(hello.AsSpan(), out _));

            pool.Add(hello);

            Assert.IsTrue(pool.TryGet(hello.AsSpan(), out string?hello2));

            Assert.AreSame(hello, hello2);
        }
コード例 #2
0
        public void Test_StringPool_Add_Misc()
        {
            var pool = new StringPool();

            string
                hello      = nameof(hello),
                helloworld = nameof(helloworld),
                windowsCommunityToolkit = nameof(windowsCommunityToolkit);

            Assert.IsFalse(pool.TryGet(hello.AsSpan(), out _));
            Assert.IsFalse(pool.TryGet(helloworld.AsSpan(), out _));
            Assert.IsFalse(pool.TryGet(windowsCommunityToolkit.AsSpan(), out _));

            pool.Add(hello);
            pool.Add(helloworld);
            pool.Add(windowsCommunityToolkit);

            Assert.IsTrue(pool.TryGet(hello.AsSpan(), out string?hello2));
            Assert.IsTrue(pool.TryGet(helloworld.AsSpan(), out string?world2));
            Assert.IsTrue(pool.TryGet(windowsCommunityToolkit.AsSpan(), out string?windowsCommunityToolkit2));

            Assert.AreSame(hello, hello2);
            Assert.AreSame(helloworld, world2);
            Assert.AreSame(windowsCommunityToolkit, windowsCommunityToolkit2);
        }
コード例 #3
0
        public void Test_StringPool_Add_Overwrite()
        {
            var pool = new StringPool();

            var today = DateTime.Today;

            var text1 = ToStringNoInlining(today);

            pool.Add(text1);

            Assert.IsTrue(pool.TryGet(text1.AsSpan(), out string?result));

            Assert.AreSame(text1, result);

            var text2 = ToStringNoInlining(today);

            pool.Add(text2);

            Assert.IsTrue(pool.TryGet(text2.AsSpan(), out result));

            Assert.AreNotSame(text1, result);
            Assert.AreSame(text2, result);
        }