Skip to content

Commit

Permalink
fix bug of TempList
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Aug 26, 2019
1 parent 7d95957 commit e4579ac
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ValueTaskSupplement/TempList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void Add(T value)
{
if (array.Length <= index)
{
var newArray = ArrayPool<T>.Shared.Rent(index);
var newArray = ArrayPool<T>.Shared.Rent(index * 2);
Array.Copy(array, newArray, index);
ArrayPool<T>.Shared.Return(array, true);
array = newArray;
Expand Down
3 changes: 3 additions & 0 deletions src/ValueTaskSupplement/_InternalVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("ValueTaskSupplement.Tests")]
38 changes: 38 additions & 0 deletions tests/ValueTaskSupplement.Tests/TempListTest.cs
Original file line number Diff line number Diff line change
@@ -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<int>(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<int>(3);

foreach (var item in Enumerable.Range(1, 100))
{
ys.Add(item);
}

ys.AsSpan().SequenceEqual(Enumerable.Range(1, 100).ToArray()).Should().BeTrue();

ys.Dispose();
}
}
}

0 comments on commit e4579ac

Please sign in to comment.