Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,41 +268,40 @@ public unsafe int Seek(
if (following >= _vectorSpan)
{
var byte0Equals = Vector.Equals(new Vector<byte>(array, index), byte0Vector);

if (byte0Equals.Equals(Vector<byte>.Zero))
if (!byte0Equals.Equals(Vector<byte>.Zero))
{
if (bytesScanned + _vectorSpan >= limit)
_block = block;

var firstEqualByteIndex = FindFirstEqualByte(byte0Equals);
var vectorBytesScanned = firstEqualByteIndex + 1;

if (bytesScanned + vectorBytesScanned > limit)
{
_block = block;
// Ensure iterator is left at limit position
_index = index + (limit - bytesScanned);
bytesScanned = limit;
return -1;
}

bytesScanned += _vectorSpan;
following -= _vectorSpan;
index += _vectorSpan;
continue;
}

_block = block;
_index = index + firstEqualByteIndex;
bytesScanned += vectorBytesScanned;

var firstEqualByteIndex = FindFirstEqualByte(ref byte0Equals);
var vectorBytesScanned = firstEqualByteIndex + 1;
return byte0;
}

if (bytesScanned + vectorBytesScanned > limit)
if (bytesScanned + _vectorSpan >= limit)
{
_block = block;
// Ensure iterator is left at limit position
_index = index + (limit - bytesScanned);
bytesScanned = limit;
return -1;
}

_index = index + firstEqualByteIndex;
bytesScanned += vectorBytesScanned;

return byte0;
bytesScanned += _vectorSpan;
following -= _vectorSpan;
index += _vectorSpan;
continue;
}
// Need unit tests to test Vector path
#if !DEBUG
Expand Down Expand Up @@ -377,35 +376,34 @@ public unsafe int Seek(
{
var byte0Equals = Vector.Equals(new Vector<byte>(array, index), byte0Vector);

if (byte0Equals.Equals(Vector<byte>.Zero))
if (!byte0Equals.Equals(Vector<byte>.Zero))
{
if (block == limit.Block && index + _vectorSpan > limit.Index)
_block = block;

var firstEqualByteIndex = FindFirstEqualByte(byte0Equals);

if (_block == limit.Block && index + firstEqualByteIndex > limit.Index)
{
_block = block;
// Ensure iterator is left at limit position
_index = limit.Index;
return -1;
}

following -= _vectorSpan;
index += _vectorSpan;
continue;
}
_index = index + firstEqualByteIndex;

_block = block;

var firstEqualByteIndex = FindFirstEqualByte(ref byte0Equals);
return byte0;
}

if (_block == limit.Block && index + firstEqualByteIndex > limit.Index)
if (block == limit.Block && index + _vectorSpan > limit.Index)
{
_block = block;
// Ensure iterator is left at limit position
_index = limit.Index;
return -1;
}

_index = index + firstEqualByteIndex;

return byte0;
following -= _vectorSpan;
index += _vectorSpan;
}
// Need unit tests to test Vector path
#if !DEBUG
Expand Down Expand Up @@ -488,16 +486,17 @@ public unsafe int Seek(
if (following >= _vectorSpan)
{
var data = new Vector<byte>(array, index);
var byte0Equals = Vector.Equals(data, byte0Vector);
var byte1Equals = Vector.Equals(data, byte1Vector);

var byte0Equals = Vector.Equals(data, byte0Vector);
if (!byte0Equals.Equals(Vector<byte>.Zero))
{
byte0Index = FindFirstEqualByte(ref byte0Equals);
byte0Index = FindFirstEqualByte(byte0Equals);
}

var byte1Equals = Vector.Equals(data, byte1Vector);
if (!byte1Equals.Equals(Vector<byte>.Zero))
{
byte1Index = FindFirstEqualByte(ref byte1Equals);
byte1Index = FindFirstEqualByte(byte1Equals);
}

if (byte0Index == int.MaxValue && byte1Index == int.MaxValue)
Expand Down Expand Up @@ -631,21 +630,23 @@ public unsafe int Seek(
if (following >= _vectorSpan)
{
var data = new Vector<byte>(array, index);
var byte0Equals = Vector.Equals(data, byte0Vector);
var byte1Equals = Vector.Equals(data, byte1Vector);
var byte2Equals = Vector.Equals(data, byte2Vector);

var byte0Equals = Vector.Equals(data, byte0Vector);
if (!byte0Equals.Equals(Vector<byte>.Zero))
{
byte0Index = FindFirstEqualByte(ref byte0Equals);
byte0Index = FindFirstEqualByte(byte0Equals);
}

var byte1Equals = Vector.Equals(data, byte1Vector);
if (!byte1Equals.Equals(Vector<byte>.Zero))
{
byte1Index = FindFirstEqualByte(ref byte1Equals);
byte1Index = FindFirstEqualByte(byte1Equals);
}

var byte2Equals = Vector.Equals(data, byte2Vector);
if (!byte2Equals.Equals(Vector<byte>.Zero))
{
byte2Index = FindFirstEqualByte(ref byte2Equals);
byte2Index = FindFirstEqualByte(byte2Equals);
}

if (byte0Index == int.MaxValue && byte1Index == int.MaxValue && byte2Index == int.MaxValue)
Expand Down Expand Up @@ -747,9 +748,9 @@ public unsafe int Seek(
/// <param name="byteEquals"></param >
/// <returns>The first index of the result vector</returns>
/// <exception cref="InvalidOperationException">byteEquals = 0</exception>
internal static int FindFirstEqualByte(ref Vector<byte> byteEquals)
internal static int FindFirstEqualByte(Vector<byte> byteEquals)
{
if (!BitConverter.IsLittleEndian) return FindFirstEqualByteSlow(ref byteEquals);
if (!BitConverter.IsLittleEndian) return FindFirstEqualByteSlow(byteEquals);

// Quasi-tree search
var vector64 = Vector.AsVectorInt64(byteEquals);
Expand All @@ -771,7 +772,7 @@ internal static int FindFirstEqualByte(ref Vector<byte> byteEquals)
}

// Internal for testing
internal static int FindFirstEqualByteSlow(ref Vector<byte> byteEquals)
internal static int FindFirstEqualByteSlow(Vector<byte> byteEquals)
{
// Quasi-tree search
var vector64 = Vector.AsVectorInt64(byteEquals);
Expand Down