summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-16 15:28:50 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-01-16 15:28:50 +0000
commit45f5e0efa10f62f712f41732613ca0246c7318ea (patch)
tree18cab9853867abdf18c0d772f1c8f9851d1f3a33 /document
parent3dde87e3ce2539a04b658a8bf6916975925ca30d (diff)
Folloup on the review comments.
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/base/idstring.cpp2
-rw-r--r--document/src/vespa/document/base/idstring.h8
-rw-r--r--document/src/vespa/document/bucket/bucketidfactory.cpp14
3 files changed, 9 insertions, 15 deletions
diff --git a/document/src/vespa/document/base/idstring.cpp b/document/src/vespa/document/base/idstring.cpp
index 288c1d38133..22a0058ff8c 100644
--- a/document/src/vespa/document/base/idstring.cpp
+++ b/document/src/vespa/document/base/idstring.cpp
@@ -136,7 +136,6 @@ validate(uint16_t numComponents)
constexpr uint32_t NAMESPACE_OFFSET = 3;
-constexpr uint32_t MAX_COMPONENTS = 4;
const vespalib::stringref DEFAULT_ID("id::::");
@@ -226,7 +225,6 @@ IdString::IdString(stringref id)
verifyIdString(id.data(), id.size());
validate(_offsets.compute(id));
-
stringref key_values(getComponent(2));
char key(0);
string::size_type pos = 0;
diff --git a/document/src/vespa/document/base/idstring.h b/document/src/vespa/document/base/idstring.h
index 894703e67fd..51d99251c2c 100644
--- a/document/src/vespa/document/base/idstring.h
+++ b/document/src/vespa/document/base/idstring.h
@@ -26,7 +26,7 @@ public:
IdString();
vespalib::stringref getNamespace() const { return getComponent(0); }
- bool hasDocType() const { return size(1 != 0); }
+ bool hasDocType() const { return size(1) != 0; }
vespalib::stringref getDocType() const { return getComponent(1); }
LocationType getLocation() const { return _location; }
bool hasNumber() const { return _has_number; }
@@ -44,7 +44,7 @@ public:
private:
size_t offset(size_t index) const { return _offsets[index]; }
- size_t size(size_t index) const { return std::max(0, _offsets[index+1] - _offsets[index] - 1); }
+ size_t size(size_t index) const { return std::max(0, int(_offsets[index+1]) - int(_offsets[index]) - 1); }
vespalib::stringref getComponent(size_t index) const { return vespalib::stringref(_rawId.c_str() + offset(index), size(index)); }
const vespalib::string & getRawId() const { return _rawId; }
@@ -55,8 +55,9 @@ private:
uint16_t operator [] (size_t i) const { return _offsets[i]; }
static const Offsets DefaultID;
private:
+ static constexpr uint32_t MAX_COMPONENTS = 4;
Offsets(vespalib::stringref id);
- uint16_t _offsets[5];
+ uint16_t _offsets[MAX_COMPONENTS + 1];
};
vespalib::string _rawId;
@@ -64,7 +65,6 @@ private:
Offsets _offsets;
uint16_t _groupOffset;
bool _has_number;
-
};
} // document
diff --git a/document/src/vespa/document/bucket/bucketidfactory.cpp b/document/src/vespa/document/bucket/bucketidfactory.cpp
index c5e75093181..c624b8900a0 100644
--- a/document/src/vespa/document/bucket/bucketidfactory.cpp
+++ b/document/src/vespa/document/bucket/bucketidfactory.cpp
@@ -42,9 +42,8 @@ BucketIdFactory::getBucketId(const DocumentId& id) const
{
uint64_t location = id.getScheme().getLocation();
assert(GlobalId::LENGTH >= sizeof(uint64_t) + 4u);
- uint64_t gid = reinterpret_cast<const uint64_t&>(*(id.getGlobalId().get() + 4));
-
-
+ uint64_t gid;
+ memcpy(&gid, id.getGlobalId().get() + 4, sizeof(gid));
return BucketId(_locationBits + _gidBits,
_initialCount | (_gidMask & gid) | (_locationMask & location));
@@ -59,12 +58,9 @@ BucketIdFactory::print(std::ostream& out, bool verbose, const std::string& inden
<< _countBits << " count bits";
if (verbose) {
out << std::hex;
- out << ",\n" << indent << " location mask: "
- << _locationMask;
- out << ",\n" << indent << " gid mask: "
- << _gidMask;
- out << ",\n" << indent << " initial count: "
- << _initialCount;
+ out << ",\n" << indent << " location mask: " << _locationMask;
+ out << ",\n" << indent << " gid mask: " << _gidMask;
+ out << ",\n" << indent << " initial count: " << _initialCount;
out << std::dec;
}
out << ")";