projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
small_vector should not require a copy-ctr from its element type unless it needs it.
[folly.git]
/
folly
/
SpookyHashV2.cpp
diff --git
a/folly/SpookyHashV2.cpp
b/folly/SpookyHashV2.cpp
index 42c7a80b25bad0e12abc286cf33c269e9b2e4cc1..a01271dac4fb83aa4b94b9230bc94ac28d40bc55 100644
(file)
--- a/
folly/SpookyHashV2.cpp
+++ b/
folly/SpookyHashV2.cpp
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 201
2
Facebook, Inc.
+ * Copyright 201
7
Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* 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
// 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 {
namespace folly {
namespace hash {
@@
-55,7
+56,7
@@
void SpookyHashV2::Short(
u.p8 = (const uint8_t *)message;
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;
{
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
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)
{
{
while (u.p64 < end)
{
@@
-197,7
+198,7
@@
void SpookyHashV2::Hash128(
remainder = (length - ((const uint8_t *)end-(const uint8_t *)message));
memcpy(buf, end, remainder);
memset(((uint8_t *)buf)+remainder, 0, sc_blockSize-remainder);
remainder = (length - ((const uint8_t *)end-(const uint8_t *)message));
memcpy(buf, end, remainder);
memset(((uint8_t *)buf)+remainder, 0, sc_blockSize-remainder);
- ((uint8_t
*)buf)[sc_blockSize-1] = remainder
;
+ ((uint8_t
*)buf)[sc_blockSize - 1] = uint8_t(remainder)
;
// do some final mixing
End(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
// do some final mixing
End(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
@@
-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));
// 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)
{
{
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
// 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)
{
// init the variables
if (m_length < sc_bufSize)
@@
-333,7
+334,9
@@
void SpookyHashV2::Final(uint64_t *hash1, uint64_t *hash2)
return;
}
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];
uint8_t remainder = m_remainder;
uint64_t h0 = m_state[0];