Skip to content

Commit 3b08e83

Browse files
authored
Optimize XxHash implementation
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 4d67cf2 commit 3b08e83

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

HashifyNet/Algorithms/XxHash/XxHash_Implementation.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,19 @@ protected override void TransformByteGroupsInternal(ReadOnlySpan<byte> data)
148148

149149
for (var currentIndex = 0; currentIndex < dataCount; currentIndex += 16)
150150
{
151-
tempA += Endianness.ToUInt32LittleEndian(data, currentIndex) * tempPrime1;
151+
tempA += Endianness.ToUInt32LittleEndian(data.Slice(currentIndex)) * tempPrime1;
152152
tempA = RotateLeft(tempA, 13);
153153
tempA *= tempPrime0;
154154

155-
tempB += Endianness.ToUInt32LittleEndian(data, currentIndex + 4) * tempPrime1;
155+
tempB += Endianness.ToUInt32LittleEndian(data.Slice(currentIndex + 4)) * tempPrime1;
156156
tempB = RotateLeft(tempB, 13);
157157
tempB *= tempPrime0;
158158

159-
tempC += Endianness.ToUInt32LittleEndian(data, currentIndex + 8) * tempPrime1;
159+
tempC += Endianness.ToUInt32LittleEndian(data.Slice(currentIndex + 8)) * tempPrime1;
160160
tempC = RotateLeft(tempC, 13);
161161
tempC *= tempPrime0;
162162

163-
tempD += Endianness.ToUInt32LittleEndian(data, currentIndex + 12) * tempPrime1;
163+
tempD += Endianness.ToUInt32LittleEndian(data.Slice(currentIndex + 12)) * tempPrime1;
164164
tempD = RotateLeft(tempD, 13);
165165
tempD *= tempPrime0;
166166
}
@@ -199,7 +199,7 @@ protected override IHashValue FinalizeHashValueInternal(ReadOnlySpan<byte> lefto
199199

200200
for (var currentOffset = 0; currentOffset < endOffset; currentOffset += 4)
201201
{
202-
hashValue += Endianness.ToUInt32LittleEndian(leftover, currentOffset) * _primes32[2];
202+
hashValue += Endianness.ToUInt32LittleEndian(leftover.Slice(currentOffset)) * _primes32[2];
203203
hashValue = RotateLeft(hashValue, 17) * _primes32[3];
204204
}
205205
}
@@ -304,19 +304,19 @@ protected override void TransformByteGroupsInternal(ReadOnlySpan<byte> data)
304304

305305
for (var currentIndex = 0; currentIndex < dataCount; currentIndex += 32)
306306
{
307-
tempA += Endianness.ToUInt64LittleEndian(data, currentIndex) * tempPrime1;
307+
tempA += Endianness.ToUInt64LittleEndian(data.Slice(currentIndex)) * tempPrime1;
308308
tempA = RotateLeft(tempA, 31);
309309
tempA *= tempPrime0;
310310

311-
tempB += Endianness.ToUInt64LittleEndian(data, currentIndex + 8) * tempPrime1;
311+
tempB += Endianness.ToUInt64LittleEndian(data.Slice(currentIndex + 8)) * tempPrime1;
312312
tempB = RotateLeft(tempB, 31);
313313
tempB *= tempPrime0;
314314

315-
tempC += Endianness.ToUInt64LittleEndian(data, currentIndex + 16) * tempPrime1;
315+
tempC += Endianness.ToUInt64LittleEndian(data.Slice(currentIndex + 16)) * tempPrime1;
316316
tempC = RotateLeft(tempC, 31);
317317
tempC *= tempPrime0;
318318

319-
tempD += Endianness.ToUInt64LittleEndian(data, currentIndex + 24) * tempPrime1;
319+
tempD += Endianness.ToUInt64LittleEndian(data.Slice(currentIndex + 24)) * tempPrime1;
320320
tempD = RotateLeft(tempD, 31);
321321
tempD *= tempPrime0;
322322
}
@@ -389,7 +389,7 @@ protected override IHashValue FinalizeHashValueInternal(ReadOnlySpan<byte> lefto
389389
// In 8-byte chunks, process all full chunks
390390
for (int x = 0; x < leftover.Length / 8; ++x)
391391
{
392-
hashValue ^= RotateLeft(Endianness.ToUInt64LittleEndian(leftover, x * 8) * _primes64[1], 31) * _primes64[0];
392+
hashValue ^= RotateLeft(Endianness.ToUInt64LittleEndian(leftover.Slice(x * 8)) * _primes64[1], 31) * _primes64[0];
393393
hashValue = (RotateLeft(hashValue, 27) * _primes64[0]) + _primes64[3];
394394
}
395395

@@ -398,7 +398,7 @@ protected override IHashValue FinalizeHashValueInternal(ReadOnlySpan<byte> lefto
398398
{
399399
var startOffset = remainderLength - (remainderLength % 8);
400400

401-
hashValue ^= Endianness.ToUInt32LittleEndian(leftover, startOffset) * _primes64[0];
401+
hashValue ^= Endianness.ToUInt32LittleEndian(leftover.Slice(startOffset)) * _primes64[0];
402402
hashValue = (RotateLeft(hashValue, 23) * _primes64[1]) + _primes64[2];
403403
}
404404

0 commit comments

Comments
 (0)