コード例 #1
0
    public void TestEdgeOfRegion1_DoesntFit()
    {
        var stack = new ChunkStack <int>();

        var span1 = stack.Allocate(510);

        Assert.Equal(510, span1.Length);

        var span2 = stack.Allocate(3);

        Assert.Equal(3, span2.Length);

        stack.Free(span2);
        stack.Free(span1);
        stack.Dispose();
    }
コード例 #2
0
    public void TestLargeChunk_Region2()
    {
        var stack = new ChunkStack <int>();

        var span1 = stack.Allocate(512);

        Assert.Equal(512, span1.Length);

        var span2 = stack.Allocate(513);

        Assert.Equal(513, span2.Length);

        stack.Free(span2);
        stack.Free(span1);
        stack.Dispose();
    }
コード例 #3
0
    public void TestEmptyChunk()
    {
        var stack = new ChunkStack <int>();
        var span  = stack.Allocate(0);

        Assert.Equal(0, span.Length);

        stack.Free(span);
        stack.Dispose();
    }
コード例 #4
0
    public void TestLargeChunk_Region1()
    {
        var stack = new ChunkStack <int>();

        var span = stack.Allocate(513);

        Assert.Equal(513, span.Length);

        stack.Free(span);
        stack.Dispose();
    }
コード例 #5
0
    public void TestSomeSmallChunks()
    {
        var stack = new ChunkStack <int>();

        var span1 = stack.Allocate(1);

        Assert.Equal(1, span1.Length);

        var span2 = stack.Allocate(2);

        Assert.Equal(2, span2.Length);

        var previousValues = span2.ToArray();

        span1[0]++;
        Assert.Equal(previousValues, span2.ToArray());

        stack.Free(span2);
        stack.Free(span1);
        stack.Dispose();
    }
コード例 #6
0
    public void TestEdgeOfRegion2_Fits()
    {
        var stack = new ChunkStack <int>();

        var span1 = stack.Allocate(512);

        Assert.Equal(512, span1.Length);

        var span2 = stack.Allocate(510);

        Assert.Equal(510, span2.Length);

        var span3 = stack.Allocate(2);

        Assert.Equal(2, span3.Length);

        stack.Free(span3);
        stack.Free(span2);
        stack.Free(span1);
        stack.Dispose();
    }
コード例 #7
0
    internal static R WithChildren <T, R>(
        this IRewriter <T> rewriter,
        SpanFunc <T, R> action,
        T value,
        ref ChunkStack <T> chunks
        )
    {
        var count = rewriter.CountChildren(value);

        if (count <= 4)
        {
            return(WithChildren_Fast(rewriter, action, value, count));
        }

        var span = chunks.Allocate(count);

        rewriter.GetChildren(span, value);
        var result = action(span);

        chunks.Free(span);
        return(result);
    }