@@ -25,28 +25,23 @@ protected override void HashCore(byte[] array, int ibStart, int cbSize)
25
25
{
26
26
Length += cbSize ;
27
27
if ( cbSize > 0 )
28
- {
29
- var blocks = ( cbSize / 4 ) ;
30
- var remainder = ( cbSize & 3 ) ;
31
-
32
- Body ( array , ibStart , blocks , remainder ) ;
33
- }
28
+ Body ( array , ibStart , cbSize ) ;
34
29
}
35
30
36
31
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
37
- private void Body ( byte [ ] data , int offset , int blocks , int remainder )
32
+ private void Body ( byte [ ] data , int start , int length )
38
33
{
39
- // grab reference to the end of our data as uint blocks
40
- while ( blocks -- > 0 )
41
- {
42
- // get our values
43
- uint k1 = BitConverter . ToUInt32 ( data , offset ) ; offset += 4 ;
34
+ int remainder = length & 3 ;
35
+ int alignedLength = start + ( length - remainder ) ;
44
36
37
+ for ( int i = start ; i < alignedLength ; i += 4 )
38
+ {
39
+ uint k1 = BitConverter . ToUInt32 ( data , i ) ;
45
40
H1 = ( ( ( H1 ^ ( ( ( k1 * C1 ) . RotateLeft ( 15 ) ) * C2 ) ) . RotateLeft ( 13 ) ) * 5 ) + 0xe6546b64 ;
46
41
}
47
42
48
43
if ( remainder > 0 )
49
- Tail ( data , offset , remainder ) ;
44
+ Tail ( data , alignedLength , remainder ) ;
50
45
}
51
46
52
47
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -58,9 +53,9 @@ private void Tail(byte[] tail, int position, int remainder)
58
53
// determine how many bytes we have left to work with based on length
59
54
switch ( remainder )
60
55
{
61
- case 3 : k1 ^= ( uint ) tail [ position + 2 ] << 16 ; goto case 2 ;
62
- case 2 : k1 ^= ( uint ) tail [ position + 1 ] << 8 ; goto case 1 ;
63
- case 1 : k1 ^= tail [ position ] ; break ;
56
+ case 3 : k1 ^= ( uint ) tail [ position + 2 ] << 16 ; goto case 2 ;
57
+ case 2 : k1 ^= ( uint ) tail [ position + 1 ] << 8 ; goto case 1 ;
58
+ case 1 : k1 ^= tail [ position ] ; break ;
64
59
}
65
60
66
61
H1 = H1 ^ ( ( k1 * C1 ) . RotateLeft ( 15 ) * C2 ) ;
0 commit comments