summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-23 11:59:54 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-01-23 11:59:54 +0000
commit7a97a9c569be961b79bea5990296f414d7f3f935 (patch)
treee0dbb1f258ad065687e4cf8fd07ccd372bdd56ae /document
parente7f0c18c77929909632121f9baa52805addc4842 (diff)
Avoid duplicating information.
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/base/idstring.cpp1
-rw-r--r--document/src/vespa/document/base/idstring.h10
2 files changed, 6 insertions, 5 deletions
diff --git a/document/src/vespa/document/base/idstring.cpp b/document/src/vespa/document/base/idstring.cpp
index 22a0058ff8c..930668b2fac 100644
--- a/document/src/vespa/document/base/idstring.cpp
+++ b/document/src/vespa/document/base/idstring.cpp
@@ -194,7 +194,6 @@ IdString::Offsets::compute(stringref id)
for (;index < VESPA_NELEMS(_offsets); index++) {
_offsets[index] = id.size() + 1; // 1 is added due to the implicitt accounting for ':'
}
- _offsets[MAX_COMPONENTS] = id.size() + 1; // 1 is added due to the implicitt accounting for ':'
return numComponents;
}
diff --git a/document/src/vespa/document/base/idstring.h b/document/src/vespa/document/base/idstring.h
index 51d99251c2c..90f307553e8 100644
--- a/document/src/vespa/document/base/idstring.h
+++ b/document/src/vespa/document/base/idstring.h
@@ -35,7 +35,9 @@ public:
vespalib::stringref getGroup() const {
return vespalib::stringref(getRawId().c_str() + _groupOffset, offset(3) - _groupOffset - 1);
}
- vespalib::stringref getNamespaceSpecific() const { return getComponent(3); }
+ vespalib::stringref getNamespaceSpecific() const {
+ return vespalib::stringref(_rawId.c_str() + offset(3), _rawId.size() - offset(3));
+ }
bool operator==(const IdString& other) const
{ return toString() == other.toString(); }
@@ -43,8 +45,8 @@ public:
const vespalib::string & toString() const { return _rawId; }
private:
- size_t offset(size_t index) const { return _offsets[index]; }
- size_t size(size_t index) const { return std::max(0, int(_offsets[index+1]) - int(_offsets[index]) - 1); }
+ uint16_t offset(uint32_t index) const { return _offsets[index]; }
+ uint16_t size(uint32_t index) const { return std::max(0, int(offset(index+1)) - int(offset(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; }
@@ -57,7 +59,7 @@ private:
private:
static constexpr uint32_t MAX_COMPONENTS = 4;
Offsets(vespalib::stringref id);
- uint16_t _offsets[MAX_COMPONENTS + 1];
+ uint16_t _offsets[MAX_COMPONENTS];
};
vespalib::string _rawId;