Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Rename Skip to Advance (#2043)
Browse files Browse the repository at this point in the history
Fixes #2042
  • Loading branch information
davidfowl authored Jan 10, 2018
1 parent e74a2eb commit ebece56
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public static bool TryRead<TSequence>(ref BufferReader<TSequence> reader, out in
{
if (BinaryPrimitives.TryReadInt32LittleEndian(unread, out value))
{
reader.Skip(sizeof(int));
reader.Advance(sizeof(int));
return true;
}
}
else if (BinaryPrimitives.TryReadInt32BigEndian(unread, out value))
{
reader.Skip(sizeof(int));
reader.Advance(sizeof(int));
return true;
}

Expand All @@ -42,7 +42,7 @@ public static bool TryRead<TSequence>(ref BufferReader<TSequence> reader, out in
{
value = BinaryPrimitives.ReadInt32BigEndian(tempSpan);
}
reader.Skip(sizeof(int));
reader.Advance(sizeof(int));
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static bool TryParse<TSequence>(ref BufferReader<TSequence> reader, out b
{
if (unread.Length > consumed)
{
reader.Skip(consumed);
reader.Advance(consumed);
return true;
}
}
Expand All @@ -25,7 +25,7 @@ public static bool TryParse<TSequence>(ref BufferReader<TSequence> reader, out b
var copied = BufferReader.Peek(reader, tempSpan);
if (Utf8Parser.TryParse(tempSpan.Slice(0, copied), out value, out consumed))
{
reader.Skip(consumed);
reader.Advance(consumed);
return true;
}

Expand All @@ -40,7 +40,7 @@ public static bool TryParse<TSequence>(ref BufferReader<TSequence> reader, out i
{
if (unread.Length > consumed)
{
reader.Skip(consumed);
reader.Advance(consumed);
return true;
}
}
Expand All @@ -49,7 +49,7 @@ public static bool TryParse<TSequence>(ref BufferReader<TSequence> reader, out i
var copied = BufferReader.Peek(reader, tempSpan);
if (Utf8Parser.TryParse(tempSpan.Slice(0, copied), out value, out consumed))
{
reader.Skip(consumed);
reader.Advance(consumed);
return true;
}

Expand All @@ -64,7 +64,7 @@ public static bool TryParse<TSequence>(ref BufferReader<TSequence> reader, out u
{
if (unread.Length > consumed)
{
reader.Skip(consumed);
reader.Advance(consumed);
return true;
}
}
Expand All @@ -73,7 +73,7 @@ public static bool TryParse<TSequence>(ref BufferReader<TSequence> reader, out u
var copied = BufferReader.Peek(reader, tempSpan);
if (Utf8Parser.TryParse(tempSpan.Slice(0, copied), out value, out consumed))
{
reader.Skip(consumed);
reader.Advance(consumed);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void MoveNext()
_end = true;
}

public void Skip(int byteCount)
public void Advance(int byteCount)
{
if (byteCount < 0)
{
Expand Down
4 changes: 2 additions & 2 deletions src/System.Text.Http.Parser/HttpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public unsafe bool ParseHeaders<T>(T handler, in ReadOnlyBuffer buffer, out Posi
// the reader's state matches what we expect
if (index == reader.Index)
{
reader.Skip(2);
reader.Advance(2);
}

done = true;
Expand Down Expand Up @@ -346,7 +346,7 @@ public unsafe bool ParseHeaders<T>(T handler, in ReadOnlyBuffer buffer, out Posi
}

// Skip the reader forward past the header line
reader.Skip(length);
reader.Advance(length);
remaining -= length;
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Benchmarks/BytesReaderBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void ParseInt32BytesReader()

using (iteration.StartMeasurement()) {
while(BufferReaderExtensions.TryParse(ref reader, out int value)) {
reader.Skip(1);
reader.Advance(1);
}
}
}
Expand All @@ -50,7 +50,7 @@ static void ParseInt32BytesRangeReader()

using (iteration.StartMeasurement()) {
while (BufferReaderExtensions.TryParse(ref reader, out int value)) {
reader.Skip(1);
reader.Advance(1);
}
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ static void ParseInt32ReadableBufferReader()
using (iteration.StartMeasurement())
{
while(Utf8Parser.TryParse(reader.CurrentSegment.Slice(reader.ConsumedBytes), out int value, out int consumed)){
reader.Skip(consumed + 1);
reader.Advance(consumed + 1);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/System.Buffers.Experimental.Tests/BytesReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ static void BytesReaderBenchmarkBaseline()
while (BufferReaderExtensions.TryParse(ref robReader, out int value))
{
robSum += value;
robReader.Skip(1);
robReader.Advance(1);
}

var brReader = BufferReader.Create(bytesRange);
long brSum = 0;
while (BufferReaderExtensions.TryParse(ref brReader, out int value))
{
brSum += value;
brReader.Skip(1);
brReader.Advance(1);
}

Assert.Equal(robSum, brSum);
Expand Down
30 changes: 15 additions & 15 deletions tests/System.Buffers.Primitives.Tests/ReadableBufferReaderFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public SingleSegment() : base(ReadOnlyBufferFactory.SingleSegment) { }
internal SingleSegment(ReadOnlyBufferFactory factory) : base(factory) { }

[Fact]
public void SkipSingleBufferSkipsBytes()
public void AdvanceSingleBufferSkipsBytes()
{
var reader = BufferReader.Create(BufferUtilities.CreateBuffer(new byte[] { 1, 2, 3, 4, 5 }));
reader.Skip(2);
reader.Advance(2);
Assert.Equal(2, reader.Index);
Assert.Equal(3, reader.CurrentSegment[reader.Index]);
Assert.Equal(3, reader.Peek());
reader.Skip(2);
reader.Advance(2);
Assert.Equal(5, reader.Peek());
Assert.Equal(4, reader.Index);
Assert.Equal(5, reader.CurrentSegment[reader.Index]);
Expand Down Expand Up @@ -114,21 +114,21 @@ public void PeekReturnsMinuOneByteInTheEnd()
}

[Fact]
public void SkipToEndThenPeekReturnsMinusOne()
public void AdvanceToEndThenPeekReturnsMinusOne()
{
var reader = BufferReader.Create(Factory.CreateWithContent(new byte[] { 1, 2, 3, 4, 5 }));
reader.Skip(5);
reader.Advance(5);
Assert.True(reader.End);
Assert.Equal(-1, reader.Peek());
}

[Fact]
public void SkippingPastLengthThrows()
public void AdvancingPastLengthThrows()
{
var reader = BufferReader.Create(Factory.CreateWithContent(new byte[] { 1, 2, 3, 4, 5 }));
try
{
reader.Skip(6);
reader.Advance(6);
Assert.True(false);
}
catch (Exception ex)
Expand All @@ -153,7 +153,7 @@ public void EmptySegmentsAreSkippedOnMoveNext()
var reader = BufferReader.Create(buffer);

Assert.Equal(1, reader.Peek());
reader.Skip(1);
reader.Advance(1);
Assert.Equal(2, reader.Peek());
}

Expand All @@ -168,25 +168,25 @@ public void PeekGoesToEndIfAllEmptySegments()
}

[Fact]
public void SkipTraversesSegments()
public void AdvanceTraversesSegments()
{
var buffer = Factory.CreateWithContent(new byte[] { 1, 2, 3 });
var reader = BufferReader.Create(buffer);

reader.Skip(2);
reader.Advance(2);
Assert.Equal(3, reader.CurrentSegment[reader.Index]);
Assert.Equal(3, reader.Take());
}

[Fact]
public void SkipThrowsPastLengthMultipleSegments()
public void AdvanceThrowsPastLengthMultipleSegments()
{
var buffer = Factory.CreateWithContent(new byte[] { 1, 2, 3 });
var reader = BufferReader.Create(buffer);

try
{
reader.Skip(4);
reader.Advance(4);
Assert.True(false);
}
catch (Exception ex)
Expand Down Expand Up @@ -294,7 +294,7 @@ public void ReaderIndexIsCorrect()
{
Assert.Equal(counter++, reader.CurrentSegment[i]);
}
reader.Skip(span.Length);
reader.Advance(span.Length);
}
Assert.Equal(buffer.Length, reader.ConsumedBytes);
}
Expand All @@ -320,7 +320,7 @@ public void CopyToLargerBufferWorks()
Assert.Equal(0, buffer[r]);
}

reader.Skip(1);
reader.Advance(1);
buffer.Clear();
}
}
Expand All @@ -347,7 +347,7 @@ public void CopyToSmallerBufferWorks()
Assert.True(bufferSlice.Slice(0, copied).SequenceEqual(content.AsSpan().Slice(i, j)));
}

reader.Skip(1);
reader.Advance(1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private static void FindAllNewLinesReadableBufferReader(ReadOnlyBuffer buffer)
}

span = span.Slice(length);
reader.Skip(skip);
reader.Advance(skip);
}
}
}
Expand Down

0 comments on commit ebece56

Please sign in to comment.