diff --git a/src/ValueTaskSupplement/TempList.cs b/src/ValueTaskSupplement/TempList.cs index eee46d3..ed5ef74 100644 --- a/src/ValueTaskSupplement/TempList.cs +++ b/src/ValueTaskSupplement/TempList.cs @@ -18,7 +18,7 @@ public void Add(T value) { if (array.Length <= index) { - var newArray = ArrayPool.Shared.Rent(index); + var newArray = ArrayPool.Shared.Rent(index * 2); Array.Copy(array, newArray, index); ArrayPool.Shared.Return(array, true); array = newArray; diff --git a/src/ValueTaskSupplement/_InternalVisibleTo.cs b/src/ValueTaskSupplement/_InternalVisibleTo.cs new file mode 100644 index 0000000..16f7af3 --- /dev/null +++ b/src/ValueTaskSupplement/_InternalVisibleTo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("ValueTaskSupplement.Tests")] \ No newline at end of file diff --git a/tests/ValueTaskSupplement.Tests/TempListTest.cs b/tests/ValueTaskSupplement.Tests/TempListTest.cs new file mode 100644 index 0000000..885a693 --- /dev/null +++ b/tests/ValueTaskSupplement.Tests/TempListTest.cs @@ -0,0 +1,38 @@ +using FluentAssertions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace ValueTaskSupplement.Tests +{ + public class TempListTest + { + [Fact] + public void Foo() + { + var xs = new TempList(6); + xs.Add(10); + xs.Add(20); + xs.Add(30); + xs.Add(40); + xs.Add(50); + + xs.AsSpan().SequenceEqual(new[] { 10, 20, 30, 40, 50 }).Should().BeTrue(); + + xs.Dispose(); + + var ys = new TempList(3); + + foreach (var item in Enumerable.Range(1, 100)) + { + ys.Add(item); + } + + ys.AsSpan().SequenceEqual(Enumerable.Range(1, 100).ToArray()).Should().BeTrue(); + + ys.Dispose(); + } + } +}