diff options
Diffstat (limited to 'xdelta3/xdelta3-hash.h')
-rw-r--r-- | xdelta3/xdelta3-hash.h | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/xdelta3/xdelta3-hash.h b/xdelta3/xdelta3-hash.h index e546d59..08d8136 100644 --- a/xdelta3/xdelta3-hash.h +++ b/xdelta3/xdelta3-hash.h | |||
@@ -65,46 +65,29 @@ xd3_large_cksum_update (uint32_t cksum, | |||
65 | /* TODO: revisit this topic */ | 65 | /* TODO: revisit this topic */ |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | /* Note: small cksum is hard-coded for 4 bytes */ | ||
69 | #if UNALIGNED_OK | 68 | #if UNALIGNED_OK |
70 | static inline uint32_t | 69 | #define UNALIGNED_READ32(dest,src) (*(dest)) = (*(uint32_t*)(src)) |
71 | xd3_scksum (uint32_t *state, | ||
72 | const uint8_t *base, | ||
73 | const usize_t look) | ||
74 | { | ||
75 | (*state) = *(uint32_t*)base; | ||
76 | return (*state) * hash_multiplier; | ||
77 | } | ||
78 | static inline uint32_t | ||
79 | xd3_small_cksum_update (uint32_t *state, | ||
80 | const uint8_t *base, | ||
81 | usize_t look) | ||
82 | { | ||
83 | (*state) = *(uint32_t*)(base+1); | ||
84 | return (*state) * hash_multiplier; | ||
85 | } | ||
86 | #else | 70 | #else |
71 | #define UNALIGNED_READ32(dest,src) memcpy((dest), (src), 4); | ||
72 | #endif | ||
73 | |||
74 | /* TODO: small cksum is hard-coded for 4 bytes (i.e., "look" is unused) */ | ||
87 | static inline uint32_t | 75 | static inline uint32_t |
88 | xd3_scksum (uint32_t *state, | 76 | xd3_scksum (uint32_t *state, |
89 | const uint8_t *base, | 77 | const uint8_t *base, |
90 | const usize_t look) | 78 | const usize_t look) |
91 | { | 79 | { |
92 | (*state) = (base[0] << 24 | | 80 | UNALIGNED_READ32(state, base); |
93 | base[1] << 16 | | ||
94 | base[2] << 8 | | ||
95 | base[3]); | ||
96 | return (*state) * hash_multiplier; | 81 | return (*state) * hash_multiplier; |
97 | } | 82 | } |
98 | static inline uint32_t | 83 | static inline uint32_t |
99 | xd3_small_cksum_update (uint32_t *state, | 84 | xd3_small_cksum_update (uint32_t *state, |
100 | const uint8_t *base, | 85 | const uint8_t *base, |
101 | const usize_t look) | 86 | usize_t look) |
102 | { | 87 | { |
103 | (*state) <<= 8; | 88 | UNALIGNED_READ32(state, base+1); |
104 | (*state) |= base[4]; | ||
105 | return (*state) * hash_multiplier; | 89 | return (*state) * hash_multiplier; |
106 | } | 90 | } |
107 | #endif | ||
108 | 91 | ||
109 | /*********************************************************************** | 92 | /*********************************************************************** |
110 | Ctable stuff | 93 | Ctable stuff |