diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/util/checksum.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/mongo/util/checksum.h b/src/mongo/util/checksum.h index fb45bd5546c..7b04b38bdc1 100644 --- a/src/mongo/util/checksum.h +++ b/src/mongo/util/checksum.h @@ -28,6 +28,7 @@ #pragma once +#include "mongo/base/data_cursor.h" #include "mongo/platform/basic.h" namespace mongo { @@ -42,18 +43,16 @@ struct Checksum { void gen(const void* buf, unsigned len) { wassert(((size_t)buf) % 8 == 0); // performance warning unsigned n = len / 8 / 2; - const unsigned long long* p = (const unsigned long long*)buf; - unsigned long long a = 0; + ConstDataCursor cdc(static_cast<const char*>(buf)); + uint64_t a = 0; for (unsigned i = 0; i < n; i++) { - a += (*p ^ i); - p++; + a += (cdc.readAndAdvance<LittleEndian<uint64_t>>() ^ i); } - unsigned long long b = 0; + uint64_t b = 0; for (unsigned i = 0; i < n; i++) { - b += (*p ^ i); - p++; + b += (cdc.readAndAdvance<LittleEndian<uint64_t>>() ^ i); } - unsigned long long c = 0; + uint64_t c = 0; for (unsigned i = n * 2 * 8; i < len; i++) { // 0-7 bytes left c = (c << 8) | ((const signed char*)buf)[i]; } |