Skip to content

Commit e07d232

Browse files
authored
Optimize Murmur Hash 2 implementation
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 88f0be8 commit e07d232

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

HashifyNet/Algorithms/MurmurHash/MurmurHash2_Implementation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected IHashValue ComputeHash32(ReadOnlySpan<byte> data, CancellationToken ca
102102

103103
for (var currentOffset = 0; currentOffset < groupEndOffset; currentOffset += 4)
104104
{
105-
uint k = Endianness.ToUInt32LittleEndian(data, currentOffset);
105+
uint k = Endianness.ToUInt32LittleEndian(data.Slice(currentOffset));
106106

107107
k *= _mixConstant32;
108108
k ^= k >> 24;
@@ -154,7 +154,7 @@ protected IHashValue ComputeHash64(ReadOnlySpan<byte> data, CancellationToken ca
154154

155155
for (var currentOffset = 0; currentOffset < groupEndOffset; currentOffset += 8)
156156
{
157-
ulong k = Endianness.ToUInt64LittleEndian(data, currentOffset);
157+
ulong k = Endianness.ToUInt64LittleEndian(data.Slice(currentOffset));
158158

159159
k *= _mixConstant64;
160160
k ^= k >> 47;
@@ -176,7 +176,7 @@ protected IHashValue ComputeHash64(ReadOnlySpan<byte> data, CancellationToken ca
176176
case 6: hashValue ^= (ulong)data[remainderOffset + 5] << 40; goto case 5;
177177
case 5: hashValue ^= (ulong)data[remainderOffset + 4] << 32; goto case 4;
178178
case 4:
179-
hashValue ^= Endianness.ToUInt32LittleEndian(data, remainderOffset);
179+
hashValue ^= Endianness.ToUInt32LittleEndian(data.Slice(remainderOffset));
180180
break;
181181

182182
case 3: hashValue ^= (ulong)data[remainderOffset + 2] << 16; goto case 2;
@@ -200,4 +200,4 @@ protected IHashValue ComputeHash64(ReadOnlySpan<byte> data, CancellationToken ca
200200
64);
201201
}
202202
}
203-
}
203+
}

0 commit comments

Comments
 (0)