Skip to content

Commit 8b7802a

Browse files
committed
AAdded comments to unit tests
1 parent ce1483b commit 8b7802a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

UnitTests/UnitTests.HighPerformance.Shared/Buffers/Test_ArrayPoolBufferWriter{T}.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ public void Test_ArrayPoolBufferWriterOfT_BufferSize(int request, int expected)
4040
{
4141
using var writer = new ArrayPoolBufferWriter<byte>();
4242

43-
writer.GetSpan(request);
43+
// Request a Span<T> of a specified size and discard it. We're just invoking this
44+
// method to force the ArrayPoolBufferWriter<T> instance to internally resize the
45+
// buffer to ensure it can contain at least this number of items. After this, we
46+
// can use reflection to get the internal array and ensure the size equals the
47+
// expected one, which matches the "round up to power of 2" logic we need. This
48+
// is documented within the resize method in ArrayPoolBufferWriter<T>, and it's
49+
// done to prevent repeated allocations of arrays in some scenarios.
50+
_ = writer.GetSpan(request);
4451

4552
var arrayFieldInfo = typeof(ArrayPoolBufferWriter<byte>).GetField("array", BindingFlags.Instance | BindingFlags.NonPublic);
4653

0 commit comments

Comments
 (0)