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

Commit

Permalink
Removed fully qualified Position names
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofCwalina committed Dec 22, 2017
1 parent db8e98e commit 3390b8b
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Buffers;
using System.Collections.Sequences;
using Position = System.Collections.Sequences.Position;

namespace Microsoft.Net
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public static int CopyTo(this IMemoryList<byte> list, Span<byte> destination)
return copied;
}

public static Collections.Sequences.Position? PositionOf(this IMemoryList<byte> list, byte value)
public static Position? PositionOf(this IMemoryList<byte> list, byte value)
{
while (list != null)
{
var current = list.Memory.Span;
var index = current.IndexOf(value);
if (index != -1) return new Collections.Sequences.Position(list, index);
if (index != -1) return new Position(list, index);
list = list.Next;
}
return null;
Expand Down Expand Up @@ -135,7 +135,7 @@ public static void Pipe(this IBufferOperation transformation, ReadOnlyBytes sour
ReadOnlySpan<byte> remainder = stackalloc byte[0];
Span<byte> stackSpan = stackalloc byte[stackLength];

Collections.Sequences.Position poisition = default;
Position poisition = default;
while (source.TryGet(ref poisition, out var sourceBuffer))
{
Span<byte> outputSpan = destination.GetSpan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public MemoryList Append(Memory<byte> bytes)

public long VirtualIndex => _virtualIndex;

public Collections.Sequences.Position First => new Collections.Sequences.Position(this, 0);
public Position First => new Position(this, 0);

public int CopyTo(Span<byte> buffer)
{
int copied = 0;
Collections.Sequences.Position position = default;
Position position = default;
var free = buffer;
while (TryGet(ref position, out ReadOnlyMemory<byte> segment, true))
{
Expand All @@ -64,14 +64,14 @@ public int CopyTo(Span<byte> buffer)
return copied;
}

public bool TryGet(ref Collections.Sequences.Position position, out ReadOnlyMemory<byte> item, bool advance = true)
public bool TryGet(ref Position position, out ReadOnlyMemory<byte> item, bool advance = true)
{
var result = TryGet(ref position, out Memory<byte> memory, advance);
item = memory;
return result;
}

public bool TryGet(ref Collections.Sequences.Position position, out Memory<byte> item, bool advance = true)
public bool TryGet(ref Position position, out Memory<byte> item, bool advance = true)
{
if (position == default)
{
Expand All @@ -81,7 +81,7 @@ public bool TryGet(ref Collections.Sequences.Position position, out Memory<byte>

var (list, index) = position.Get<MemoryList>();
item = list._data.Slice(index);
if (advance) { position = new Collections.Sequences.Position(list._next, 0); }
if (advance) { position = new Position(list._next, 0); }
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ReadOnlyBytes(IMemoryList<byte> first, IMemoryList<byte> last)
Validate();
}

public ReadOnlyBytes(Collections.Sequences.Position first, Collections.Sequences.Position last)
public ReadOnlyBytes(Position first, Position last)
{
(_start, _startIndex) = first.Get<object>();
(_end, _endIndex) = last.Get<object>();
Expand Down Expand Up @@ -134,7 +134,7 @@ public ReadOnlyBytes Slice(long index)
public ReadOnlyBytes Slice(int index)
=> Slice((long)index);

public ReadOnlyBytes Slice(Collections.Sequences.Position position)
public ReadOnlyBytes Slice(Position position)
{
var kind = Kind;
switch (kind)
Expand All @@ -143,12 +143,12 @@ public ReadOnlyBytes Slice(Collections.Sequences.Position position)
var (array, index) = position.Get<byte[]>();
return new ReadOnlyBytes(array, index, array.Length - index);
case Type.MemoryList:
return Slice(position, new Collections.Sequences.Position((IMemoryList<byte>)_end, _endIndex));
return Slice(position, new Position((IMemoryList<byte>)_end, _endIndex));
default: throw new NotImplementedException();
}
}

public ReadOnlyBytes Slice(Collections.Sequences.Position start, Collections.Sequences.Position end)
public ReadOnlyBytes Slice(Position start, Position end)
{
var kind = Kind;
switch (kind)
Expand Down Expand Up @@ -236,7 +236,7 @@ Type Kind
}
}

public Collections.Sequences.Position Start => new Collections.Sequences.Position(_start, _startIndex);
public Position Start => new Position(_start, _startIndex);

public int CopyTo(Span<byte> buffer)
{
Expand Down Expand Up @@ -270,7 +270,7 @@ public Span<byte> ToSpan()
return array;
}

public bool TryGet(ref Collections.Sequences.Position position, out ReadOnlyMemory<byte> item, bool advance = true)
public bool TryGet(ref Position position, out ReadOnlyMemory<byte> item, bool advance = true)
{
if(position == default)
{
Expand Down Expand Up @@ -299,7 +299,7 @@ public bool TryGet(ref Collections.Sequences.Position position, out ReadOnlyMemo
}
else
{
if (advance) position = new Collections.Sequences.Position(node.Next, 0);
if (advance) position = new Position(node.Next, 0);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ReadWriteBytes(IMemoryList<byte> first, IMemoryList<byte> last)
Validate();
}

public ReadWriteBytes(Collections.Sequences.Position first, Collections.Sequences.Position last)
public ReadWriteBytes(Position first, Position last)
{
(_start, _startIndex) = first.Get<object>();
(_end, _endIndex) = last.Get<object>();
Expand Down Expand Up @@ -130,7 +130,7 @@ public ReadWriteBytes Slice(long index)
public ReadWriteBytes Slice(int index)
=> Slice((long)index);

public ReadWriteBytes Slice(Collections.Sequences.Position position)
public ReadWriteBytes Slice(Position position)
{
var kind = Kind;
switch (kind)
Expand All @@ -139,12 +139,12 @@ public ReadWriteBytes Slice(Collections.Sequences.Position position)
var (array, index) = position.Get<byte[]>();
return new ReadWriteBytes(array, index, array.Length - index);
case Type.MemoryList:
return Slice(position, new Collections.Sequences.Position((IMemoryList<byte>)_end, _endIndex));
return Slice(position, new Position((IMemoryList<byte>)_end, _endIndex));
default: throw new NotImplementedException();
}
}

public ReadWriteBytes Slice(Collections.Sequences.Position start, Collections.Sequences.Position end)
public ReadWriteBytes Slice(Position start, Position end)
{
var kind = Kind;
switch (kind)
Expand Down Expand Up @@ -233,7 +233,7 @@ Type Kind
}
}

public Collections.Sequences.Position Start => new Collections.Sequences.Position(_start, _startIndex);
public Position Start => new Position(_start, _startIndex);

public int CopyTo(Span<byte> buffer)
{
Expand Down Expand Up @@ -267,7 +267,7 @@ public Span<byte> ToSpan()
return array;
}

public bool TryGet(ref Collections.Sequences.Position position, out Memory<byte> item, bool advance = true)
public bool TryGet(ref Position position, out Memory<byte> item, bool advance = true)
{
if (position == default)
{
Expand Down Expand Up @@ -296,7 +296,7 @@ public bool TryGet(ref Collections.Sequences.Position position, out Memory<byte>
}
else
{
if (advance) position = new Collections.Sequences.Position(node.Next, 0);
if (advance) position = new Position(node.Next, 0);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class Sequence
{
public static ReadOnlySpan<byte> ToSpan<T>(this T sequence) where T : ISequence<ReadOnlyMemory<byte>>
{
Collections.Sequences.Position position = sequence.Start;
Position position = sequence.Start;
ResizableArray<byte> array = new ResizableArray<byte>(1024);
while (sequence.TryGet(ref position, out ReadOnlyMemory<byte> buffer))
{
Expand All @@ -26,7 +26,7 @@ public static ReadOnlySpan<byte> ToSpan<T>(this T sequence) where T : ISequence<
// be used as a type parameter.
public static long IndexOf<TSequence>(TSequence sequence, byte value) where TSequence : ISequence<ReadOnlyMemory<byte>>
{
Collections.Sequences.Position position = sequence.Start;
Position position = sequence.Start;
int totalIndex = 0;
while (sequence.TryGet(ref position, out ReadOnlyMemory<byte> memory))
{
Expand All @@ -39,7 +39,7 @@ public static long IndexOf<TSequence>(TSequence sequence, byte value) where TSeq

public static long IndexOf<TSequence>(TSequence sequence, byte v1, byte v2) where TSequence : ISequence<ReadOnlyMemory<byte>>
{
Collections.Sequences.Position position = sequence.Start;
Position position = sequence.Start;
int totalIndex = 0;
while (sequence.TryGet(ref position, out ReadOnlyMemory<byte> memory))
{
Expand Down Expand Up @@ -68,12 +68,12 @@ public static long IndexOf<TSequence>(TSequence sequence, byte v1, byte v2) wher
return -1;
}

public static Collections.Sequences.Position? PositionOf<TSequence>(this TSequence sequence, byte value) where TSequence : ISequence<ReadOnlyMemory<byte>>
public static Position? PositionOf<TSequence>(this TSequence sequence, byte value) where TSequence : ISequence<ReadOnlyMemory<byte>>
{
if (sequence == null) return null;

Collections.Sequences.Position position = sequence.Start;
Collections.Sequences.Position result = position;
Position position = sequence.Start;
Position result = position;
while (sequence.TryGet(ref position, out ReadOnlyMemory<byte> memory))
{
var index = MemoryExtensions.IndexOf(memory.Span, value);
Expand All @@ -87,12 +87,12 @@ public static long IndexOf<TSequence>(TSequence sequence, byte v1, byte v2) wher
return null;
}

public static Collections.Sequences.Position? PositionAt<TSequence>(this TSequence sequence, long index) where TSequence : ISequence<ReadOnlyMemory<byte>>
public static Position? PositionAt<TSequence>(this TSequence sequence, long index) where TSequence : ISequence<ReadOnlyMemory<byte>>
{
if (sequence == null) return null;

Collections.Sequences.Position position = sequence.Start;
Collections.Sequences.Position result = position;
Position position = sequence.Start;
Position result = position;
while (sequence.TryGet(ref position, out ReadOnlyMemory<byte> memory))
{
var span = memory.Span;
Expand Down Expand Up @@ -123,7 +123,7 @@ public static int Copy<TSequence>(TSequence sequence, Span<byte> buffer) where T
return copied;
}

public static int Copy<TSequence>(TSequence sequence, Collections.Sequences.Position from, Span<byte> buffer) where TSequence : ISequence<ReadOnlyMemory<byte>>
public static int Copy<TSequence>(TSequence sequence, Position from, Span<byte> buffer) where TSequence : ISequence<ReadOnlyMemory<byte>>
{
int copied = 0;
while (sequence.TryGet(ref from, out ReadOnlyMemory<byte> memory, true))
Expand Down Expand Up @@ -162,7 +162,7 @@ public static bool TryParse<TSequence>(TSequence sequence, out int value, out in
return false;
}

public static bool TryParse<TSequence>(TSequence sequence, out int value, out Collections.Sequences.Position consumed) where TSequence : ISequence<ReadOnlyMemory<byte>>
public static bool TryParse<TSequence>(TSequence sequence, out int value, out Position consumed) where TSequence : ISequence<ReadOnlyMemory<byte>>
{
if(!TryParse(sequence, out value, out int consumedBytes))
{
Expand Down
20 changes: 10 additions & 10 deletions src/System.Buffers.Experimental/System/Buffers/Text/BufferReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace System.Buffers.Text
public ref struct BufferReader<TSequence> where TSequence : ISequence<ReadOnlyMemory<byte>>
{
readonly TSequence _bytes;
Collections.Sequences.Position _currentSegmentPosition;
Collections.Sequences.Position _nextSegmentPosition;
Position _currentSegmentPosition;
Position _nextSegmentPosition;
ReadOnlySpan<byte> _currentSpan;
int _currentSpanIndex;

Expand Down Expand Up @@ -62,7 +62,7 @@ public bool IsEmpty {
return false;
}

Collections.Sequences.Position position = _nextSegmentPosition;
Position position = _nextSegmentPosition;
while (_bytes.TryGet(ref position, out ReadOnlyMemory<byte> next))
{
if (!next.IsEmpty) return false;
Expand Down Expand Up @@ -175,7 +175,7 @@ private void AdvanceNextSegment(long count, int currentSegmentUnread)
Advance(count - currentSegmentUnread);
}

public void Advance(Collections.Sequences.Position position)
public void Advance(Position position)
{
_currentSegmentPosition = position;
_nextSegmentPosition = position;
Expand Down Expand Up @@ -302,9 +302,9 @@ public bool TryRead(out int value, bool littleEndian = false)

ReadOnlySpan<byte> Unread => _currentSpan.Slice(_currentSpanIndex);

Collections.Sequences.Position Position =>_currentSegmentPosition + _currentSpanIndex;
Position Position =>_currentSegmentPosition + _currentSpanIndex;

Collections.Sequences.Position? AdvanceToDelimiter(byte value)
Position? AdvanceToDelimiter(byte value)
{
var unread = Unread;
var index = unread.IndexOf(value);
Expand Down Expand Up @@ -338,7 +338,7 @@ public bool TryRead(out int value, bool littleEndian = false)
return null;
}

Collections.Sequences.Position? PositionOf(ReadOnlySpan<byte> value)
Position? PositionOf(ReadOnlySpan<byte> value)
{
var unread = Unread;
var index = unread.IndexOf(value);
Expand Down Expand Up @@ -394,10 +394,10 @@ public static BufferReader<T> Create<T>(T sequence) where T : ISequence<ReadOnly

struct PositionRange
{
public readonly Collections.Sequences.Position Start;
public readonly Collections.Sequences.Position End;
public readonly Position Start;
public readonly Position End;

public PositionRange(Collections.Sequences.Position start, Collections.Sequences.Position end)
public PositionRange(Position start, Position end)
{
Start = start;
End = end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Buffers;
using System.Buffers.Text;
using System.Collections.Sequences;
using Position = System.Collections.Sequences.Position;

namespace System.Text.Formatting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Buffers;
using System.Buffers.Text;
using System.Collections.Sequences;
using Position = System.Collections.Sequences.Position;

namespace System.Text.Parsing
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.Text.Http.Parser/HttpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public unsafe bool ParseHeaders<T>(ref T handler, ReadOnlyBytes buffer, out int
{
var index = 0;
consumedBytes = 0;
Collections.Sequences.Position position = buffer.Start;
Position position = buffer.Start;

if(!buffer.TryGet(ref position, out ReadOnlyMemory<byte> currentMemory))
{
Expand Down
Loading

0 comments on commit 3390b8b

Please sign in to comment.