Skip to content

Commit eee85c7

Browse files
authored
Refactor byte conversion to use Endianness utility
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 4bc08e2 commit eee85c7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

HashifyNet/Algorithms/Jenkins/JenkinsLookup2_Implementation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ protected override void TransformByteGroupsInternal(ArraySegment<byte> data)
112112

113113
for (var currentOffset = data.Offset; currentOffset < endOffset; currentOffset += 12)
114114
{
115-
tempA += BitConverter.ToUInt32(dataArray, currentOffset);
116-
tempB += BitConverter.ToUInt32(dataArray, currentOffset + 4);
117-
tempC += BitConverter.ToUInt32(dataArray, currentOffset + 8);
115+
tempA += Endianness.ToUInt32LittleEndian(dataArray, currentOffset);
116+
tempB += Endianness.ToUInt32LittleEndian(dataArray, currentOffset + 4);
117+
tempC += Endianness.ToUInt32LittleEndian(dataArray, currentOffset + 8);
118118

119119
Mix(ref tempA, ref tempB, ref tempC);
120120
}
@@ -147,15 +147,15 @@ protected override IHashValue FinalizeHashValueInternal(CancellationToken cancel
147147
// the first byte of c is reserved for the length
148148

149149
case 8:
150-
finalB += BitConverter.ToUInt32(remainder, 4);
150+
finalB += Endianness.ToUInt32LittleEndian(remainder, 4);
151151
goto case 4;
152152

153153
case 7: finalB += (uint)remainder[6] << 16; goto case 6;
154154
case 6: finalB += (uint)remainder[5] << 8; goto case 5;
155155
case 5: finalB += remainder[4]; goto case 4;
156156

157157
case 4:
158-
finalA += BitConverter.ToUInt32(remainder, 0);
158+
finalA += Endianness.ToUInt32LittleEndian(remainder, 0);
159159
break;
160160

161161
case 3: finalA += (uint)remainder[2] << 16; goto case 2;
@@ -170,7 +170,7 @@ protected override IHashValue FinalizeHashValueInternal(CancellationToken cancel
170170
Mix(ref finalA, ref finalB, ref finalC);
171171

172172
return new HashValue(
173-
BitConverter.GetBytes(finalC),
173+
Endianness.GetBytesLittleEndian(finalC),
174174
32);
175175
}
176176

@@ -190,4 +190,4 @@ private static void Mix(ref uint a, ref uint b, ref uint c)
190190
}
191191
}
192192
}
193-
}
193+
}

0 commit comments

Comments
 (0)