Adds style cop (#109)

This commit is contained in:
Kamron Batman 2020-04-26 00:16:02 -07:00 committed by GitHub
parent 3e715bcb60
commit 556a17aba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1725 changed files with 33831 additions and 38046 deletions

View file

@ -75,10 +75,10 @@ namespace System.Buffers
{
if (length < 0)
{
Debug.Assert(usingSequence, "usingSequence");
// Cast-away readonly to initialize lazy field
Volatile.Write(ref Unsafe.AsRef(length), sequence.Length);
}
return length;
}
}
@ -139,27 +139,25 @@ namespace System.Buffers
}
else
{
throw new ArgumentOutOfRangeException($"Rewind went past the start of the memory by {count}.", nameof(count));
throw new ArgumentOutOfRangeException(nameof(count), $"Rewind went past the start of the memory by {count}.");
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private void RetreatToPreviousSpan(long consumed)
{
Debug.Assert(usingSequence, "usingSequence");
ResetReader();
Advance(consumed);
}
private void ResetReader()
{
Debug.Assert(usingSequence, "usingSequence");
CurrentSpanIndex = 0;
Consumed = 0;
currentPosition = sequence.Start;
nextPosition = currentPosition;
if (sequence.TryGet(ref nextPosition, out ReadOnlyMemory<T> memory))
if (sequence.TryGet(ref nextPosition, out var memory))
{
moreData = true;
@ -184,11 +182,10 @@ namespace System.Buffers
private void GetNextSpan()
{
Debug.Assert(usingSequence, "usingSequence");
if (!sequence.IsSingleSegment)
{
SequencePosition previousNextPosition = nextPosition;
while (sequence.TryGet(ref nextPosition, out ReadOnlyMemory<T> memory))
var previousNextPosition = nextPosition;
while (sequence.TryGet(ref nextPosition, out var memory))
{
currentPosition = previousNextPosition;
if (memory.Length > 0)
@ -203,6 +200,7 @@ namespace System.Buffers
previousNextPosition = nextPosition;
}
}
moreData = false;
}
@ -234,13 +232,12 @@ namespace System.Buffers
private void AdvanceToNextSpan(long count)
{
Debug.Assert(usingSequence, "usingSequence");
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
Consumed += count;
while (moreData)
{
int remaining = CurrentSpan.Length - CurrentSpanIndex;
var remaining = CurrentSpan.Length - CurrentSpanIndex;
if (remaining > count)
{
@ -253,7 +250,6 @@ namespace System.Buffers
// push the current index to the end of the span.
CurrentSpanIndex += remaining;
count -= remaining;
Debug.Assert(count >= 0);
GetNextSpan();
@ -275,7 +271,7 @@ namespace System.Buffers
// We don't provide an advance option to allow easier utilizing of stack allocated destination spans.
// (Because we can make this method readonly we can guarantee that we won't capture the span.)
ReadOnlySpan<T> firstSpan = UnreadSpan;
var firstSpan = UnreadSpan;
if (firstSpan.Length >= destination.Length)
{
firstSpan.Slice(0, destination.Length).CopyTo(destination);
@ -292,17 +288,16 @@ namespace System.Buffers
if (Remaining < destination.Length)
return false;
ReadOnlySpan<T> firstSpan = UnreadSpan;
Debug.Assert(firstSpan.Length < destination.Length);
var firstSpan = UnreadSpan;
firstSpan.CopyTo(destination);
int copied = firstSpan.Length;
var copied = firstSpan.Length;
SequencePosition next = nextPosition;
while (sequence.TryGet(ref next, out ReadOnlyMemory<T> nextSegment))
var next = nextPosition;
while (sequence.TryGet(ref next, out var nextSegment))
if (nextSegment.Length > 0)
{
ReadOnlySpan<T> nextSpan = nextSegment.Span;
int toCopy = Math.Min(nextSpan.Length, destination.Length - copied);
var nextSpan = nextSegment.Span;
var toCopy = Math.Min(nextSpan.Length, destination.Length - copied);
nextSpan.Slice(0, toCopy).CopyTo(destination.Slice(copied));
copied += toCopy;
if (copied >= destination.Length) break;