Skip to content

Commit

Permalink
Fixed array writer reset
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn committed Nov 23, 2023
1 parent a3838e3 commit 9a5ffc1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/HotChocolate/Utilities/src/Utilities/ArrayWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public Span<byte> GetSpan(int sizeHint = 0)
EnsureBufferCapacity(size);
return _buffer.AsSpan().Slice(_start, size);
}

/// <summary>
/// Gets the buffer as an <see cref="ArraySegment{T}"/>
/// </summary>
Expand Down Expand Up @@ -204,7 +204,11 @@ private void EnsureBufferCapacity(int neededCapacity)
}
}

public void Reset() => _start = 0;
public void Reset()
{
_capacity = _buffer.Length;
_start = 0;
}

/// <inheritdoc/>
public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,18 @@ public void ShouldAllocateSufficientMemory()
writer.Advance (0x2000) ;
writer.GetSpan (0x7000) ;
}

[Fact]
public void ShouldResetCapacity()
{
// Arrange
using var writer = new ArrayWriter();

// Act
writer.GetSpan(1000);
writer.Advance(1000);
writer.Reset();
writer.GetSpan(2000);
writer.Advance(2000);
}
}

0 comments on commit 9a5ffc1

Please sign in to comment.