X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FSpookyHashV2.cpp;h=b945bc6f49badd6dafb63c6ab786b7fbb4ec8d52;hb=76663af23df01607f74c00c449852f71e5d3f771;hp=c7ecaf6ac43caed4902194252f80d2bf3d3c2473;hpb=ce64f0f685111ac24c7a321ea56d0c3524621df1;p=folly.git diff --git a/folly/SpookyHashV2.cpp b/folly/SpookyHashV2.cpp index c7ecaf6a..b945bc6f 100644 --- a/folly/SpookyHashV2.cpp +++ b/folly/SpookyHashV2.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,13 +23,14 @@ // April 10 2012: buffer overflow on platforms without unaligned reads // July 12 2012: was passing out variables in final to in/out in short // July 30 2012: I reintroduced the buffer overflow -// August 5 2012: SpookyV2: d = should be d += in short hash, and remove extra mix from long hash +// August 5 2012: SpookyV2: d = should be d += in short hash, and remove +// extra mix from long hash #include -#include +#include -#define ALLOW_UNALIGNED_READS 1 +#include namespace folly { namespace hash { @@ -55,7 +56,7 @@ void SpookyHashV2::Short( u.p8 = (const uint8_t *)message; - if (!ALLOW_UNALIGNED_READS && (u.i & 0x7)) + if (!kHasUnalignedAccess && (u.i & 0x7)) { memcpy(buf, message, length); u.p64 = buf; @@ -175,7 +176,7 @@ void SpookyHashV2::Hash128( end = u.p64 + (length/sc_blockSize)*sc_numVars; // handle all whole sc_blockSize blocks of bytes - if (ALLOW_UNALIGNED_READS || ((u.i & 0x7) == 0)) + if (kHasUnalignedAccess || ((u.i & 0x7) == 0)) { while (u.p64 < end) { @@ -283,7 +284,7 @@ void SpookyHashV2::Update(const void *message, size_t length) // handle all whole blocks of sc_blockSize bytes end = u.p64 + (length/sc_blockSize)*sc_numVars; remainder = (uint8_t)(length-((const uint8_t *)end-u.p8)); - if (ALLOW_UNALIGNED_READS || (u.i & 0x7) == 0) + if (kHasUnalignedAccess || (u.i & 0x7) == 0) { while (u.p64 < end) { @@ -322,7 +323,7 @@ void SpookyHashV2::Update(const void *message, size_t length) // report the hash for the concatenation of all message fragments so far -void SpookyHashV2::Final(uint64_t *hash1, uint64_t *hash2) +void SpookyHashV2::Final(uint64_t *hash1, uint64_t *hash2) const { // init the variables if (m_length < sc_bufSize) @@ -333,7 +334,9 @@ void SpookyHashV2::Final(uint64_t *hash1, uint64_t *hash2) return; } - const uint64_t *data = (const uint64_t *)m_data; + uint64_t buf[2*sc_numVars]; + memcpy(buf, m_data, sizeof(buf)); + uint64_t *data = buf; uint8_t remainder = m_remainder; uint64_t h0 = m_state[0];