From be6e6f9a4227ac09692ba5611331dc39f166e36b Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 1 Apr 2019 15:18:21 +0000 Subject: union and casting -> memcpy explicit constructors. T -> ChecksumType. --- .../proton/documentmetastore/documentmetastore_test.cpp | 4 ++-- .../searchcore/proton/bucketdb/checksumaggregators.cpp | 15 ++++++--------- .../searchcore/proton/bucketdb/checksumaggregators.h | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) (limited to 'searchcore') diff --git a/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp b/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp index 7e16094bbf1..42d038e6b88 100644 --- a/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp +++ b/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp @@ -774,7 +774,7 @@ TEST("requireThatWeCanSortGids") } } -template +template void requireThatBasicBucketInfoWorks() { @@ -813,7 +813,7 @@ requireThatBasicBucketInfoWorks() m.erase(std::make_pair(bucketId, gid)); } assert(!m.empty()); - T cksum(BucketChecksum(0)); + ChecksumType cksum(BucketChecksum(0)); BucketId prevBucket = m.begin()->first.first; uint32_t cnt = 0u; uint32_t maxcnt = 0u; diff --git a/searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.cpp b/searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.cpp index f56d29bb82d..a118f416b6b 100644 --- a/searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.cpp +++ b/searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.cpp @@ -12,14 +12,10 @@ using GlobalId = ChecksumAggregator::GlobalId; namespace { uint32_t -gidChecksum(const document::GlobalId &gid) +gidChecksum(const GlobalId &gid) { - union { - const unsigned char *_c; - const uint32_t *_i; - } u; - u._c = gid.get(); - const uint32_t *i = u._i; + uint32_t i[3]; + memcpy(i, gid.get(), GlobalId::LENGTH); return i[0] + i[1] + i[2]; } @@ -106,8 +102,9 @@ XXH64ChecksumAggregator::empty() const { return _checksum == 0; } uint64_t XXH64ChecksumAggregator::compute(const GlobalId &gid, const Timestamp ×tamp) { char buffer[20]; - memcpy(&buffer[0], gid.get(), 12); - reinterpret_cast(&buffer[12])[0] = timestamp.getValue(); + memcpy(&buffer[0], gid.get(), GlobalId::LENGTH); + uint64_t tmp = timestamp.getValue(); + memcpy(&buffer[GlobalId::LENGTH], &tmp, sizeof(tmp)); return XXH64(buffer, sizeof(buffer), 0); } diff --git a/searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.h b/searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.h index 6d6f1b7f842..49762ad107f 100644 --- a/searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.h +++ b/searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.h @@ -9,7 +9,7 @@ namespace proton::bucketdb { **/ class LegacyChecksumAggregator : public ChecksumAggregator { public: - LegacyChecksumAggregator(BucketChecksum seed) : _checksum(seed) { } + explicit LegacyChecksumAggregator(BucketChecksum seed) : _checksum(seed) { } LegacyChecksumAggregator * clone() const override; LegacyChecksumAggregator & addDoc(const GlobalId &gid, const Timestamp ×tamp) override; LegacyChecksumAggregator & removeDoc(const GlobalId &gid, const Timestamp ×tamp) override; @@ -26,7 +26,7 @@ private: **/ class XXH64ChecksumAggregator : public ChecksumAggregator { public: - XXH64ChecksumAggregator(BucketChecksum seed) : _checksum(seed) { } + explicit XXH64ChecksumAggregator(BucketChecksum seed) : _checksum(seed) { } XXH64ChecksumAggregator * clone() const override; XXH64ChecksumAggregator & addDoc(const GlobalId &gid, const Timestamp ×tamp) override; XXH64ChecksumAggregator & removeDoc(const GlobalId &gid, const Timestamp ×tamp) override; -- cgit v1.2.3