Adding addTaskFuture and addTaskRemoteFuture to FiberManager.
[folly.git] / folly / SpookyHashV2.cpp
index 45f640ab2960adcfc2c4d06bcd33716160bf6884..877e0e7295c2184d8dfb99e804302264b9eea0fb 100644 (file)
 
 #include <folly/SpookyHashV2.h>
 
-#include <cstring>
+#include <folly/Portability.h>
 
-#define ALLOW_UNALIGNED_READS 1
+#include <cstring>
 
 namespace folly {
 namespace hash {
 
+static constexpr auto kAllowUnalignedReads = bool(FOLLY_HAVE_UNALIGNED_READS);
+
 //
 // short hash ... it could be used on any message,
 // but it's used by Spooky just for short messages.
@@ -56,7 +58,7 @@ void SpookyHashV2::Short(
 
     u.p8 = (const uint8_t *)message;
 
-    if (!ALLOW_UNALIGNED_READS && (u.i & 0x7))
+    if (!kAllowUnalignedReads && (u.i & 0x7))
     {
         memcpy(buf, message, length);
         u.p64 = buf;
@@ -176,7 +178,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 (kAllowUnalignedReads || ((u.i & 0x7) == 0))
     {
         while (u.p64 < end)
         {
@@ -284,7 +286,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 (kAllowUnalignedReads || (u.i & 0x7) == 0)
     {
         while (u.p64 < end)
         {
@@ -323,7 +325,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)
@@ -334,7 +336,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];