summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-04-01 15:18:21 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-04-01 15:18:21 +0000
commitbe6e6f9a4227ac09692ba5611331dc39f166e36b (patch)
tree6e7ae9768de52c475d223cc17deddee8da35a389 /searchcore
parentd35e7e3740bba3eaba65c7f069263172b0bb8fd1 (diff)
union and casting -> memcpy
explicit constructors. T -> ChecksumType.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp4
-rw-r--r--searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.cpp15
-rw-r--r--searchcore/src/vespa/searchcore/proton/bucketdb/checksumaggregators.h4
3 files changed, 10 insertions, 13 deletions
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 <typename T>
+template <typename ChecksumType>
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 &timestamp) {
char buffer[20];
- memcpy(&buffer[0], gid.get(), 12);
- reinterpret_cast<uint64_t *>(&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 &timestamp) override;
LegacyChecksumAggregator & removeDoc(const GlobalId &gid, const Timestamp &timestamp) 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 &timestamp) override;
XXH64ChecksumAggregator & removeDoc(const GlobalId &gid, const Timestamp &timestamp) override;