Skip to content

Commit

Permalink
sequence equal will be handled by the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
lewing committed Feb 10, 2025
1 parent 92b66ab commit d67d10b
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/tasks/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,33 +255,18 @@ protected static bool ContentEqual(Readable<TContent, TReader> streamA, Readable
return false;

int overlap = Math.Min(readA - consumedA, readB - consumedB);
if (!SequenceEqual(bufferA, consumedA, bufferB, consumedB, overlap))
if (!bufferA.AsSpan(consumedA, overlap).SequenceEqual(bufferB.AsSpan(consumedB, overlap)))
return false;

consumedA += overlap;
consumedB += overlap;
}

static bool SequenceEqual(TContent[] bufferA, int offsetA, TContent[] bufferB, int offsetB, int count)
{
#if NET
return bufferA.AsSpan(offsetA, count).SequenceEqual(bufferB.AsSpan(offsetB, count));
#else
for (int i = 0; i < count; i++)
{
if (!bufferA[offsetA + i].Equals(bufferB[offsetB + i]))
return false;
}

return true;
#endif
}
}
}

private sealed class TextFileComparer : Readable<char, StreamReader>
{
private const int _charCount = 4096;
private const int _charCount = 8192 / sizeof(char);
private TextFileComparer(string path) : base(new StreamReader(path, Encoding.UTF8, true, _charCount)) { }
protected override int Read(char[] buffer, int offset, int count) => _reader.Read(buffer, offset, count);
public static bool ContentEqual(string filePath1, string filePath2)
Expand Down

0 comments on commit d67d10b

Please sign in to comment.