diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-01-15 15:16:44 -0500 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-01-22 07:47:22 -0500 |
commit | f73316532f829cd6dd95f8fdfe440e3c5d7e7fd1 (patch) | |
tree | 1d1f98b362a6754fa5910882bdc1a2f9bd085b1b /src/mongo/util/checksum.h | |
parent | 153bc4fd12610ba0c1f53e5b6cbdeaa9df574b32 (diff) | |
download | mongo-f73316532f829cd6dd95f8fdfe440e3c5d7e7fd1.tar.gz |
SERVER-20266 Use ConstDataCursor to read buffer in Checksum::gen
Diffstat (limited to 'src/mongo/util/checksum.h')
-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]; } |