summaryrefslogtreecommitdiffstats
path: root/src/zix/digest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zix/digest.c')
-rw-r--r--src/zix/digest.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/zix/digest.c b/src/zix/digest.c
index 4e8e974..04f48f0 100644
--- a/src/zix/digest.c
+++ b/src/zix/digest.c
@@ -31,25 +31,26 @@ zix_digest_start(void)
}
ZIX_API uint32_t
-zix_digest_add(uint32_t hash, const void* buf, const size_t len)
+zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
{
+ const uint8_t* str = (const uint8_t*)buf;
#ifdef __SSE4_2__
// SSE 4.2 CRC32
for (size_t i = 0; i < (len / sizeof(uint32_t)); ++i) {
- hash = _mm_crc32_u32(hash, *(uint32_t*)buf);
- buf += sizeof(uint32_t);
+ hash = _mm_crc32_u32(hash, *(uint32_t*)str);
+ str += sizeof(uint32_t);
}
if (len & sizeof(uint16_t)) {
- hash = _mm_crc32_u16(hash, *(uint16_t*)buf);
- buf += sizeof(uint16_t);
+ hash = _mm_crc32_u16(hash, *(uint16_t*)str);
+ str += sizeof(uint16_t);
}
if (len & sizeof(uint8_t)) {
- hash = _mm_crc32_u8(hash, *(uint8_t*)buf);
+ hash = _mm_crc32_u8(hash, *(uint8_t*)str);
}
#else
// Classic DJB hash
for (size_t i = 0; i < len; ++i) {
- hash = (hash << 5) + hash + ((const uint8_t*)buf)[i];
+ hash = (hash << 5) + hash + str[i];
}
#endif
return hash;