summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3-hash.h')
-rw-r--r--xdelta3/xdelta3-hash.h33
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
70static inline uint32_t 69#define UNALIGNED_READ32(dest,src) (*(dest)) = (*(uint32_t*)(src))
71xd3_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}
78static inline uint32_t
79xd3_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) */
87static inline uint32_t 75static inline uint32_t
88xd3_scksum (uint32_t *state, 76xd3_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}
98static inline uint32_t 83static inline uint32_t
99xd3_small_cksum_update (uint32_t *state, 84xd3_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