/*
- * Copyright 2013 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.
// 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 "folly/SpookyHashV2.h"
+#include <folly/SpookyHashV2.h>
-#include <cstring>
+#include <folly/Portability.h>
-#define ALLOW_UNALIGNED_READS 1
+#include <cstring>
namespace folly {
namespace hash {
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;
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)
{
// 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)
{
// 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)
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];