From 7a97a9c569be961b79bea5990296f414d7f3f935 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 23 Jan 2020 11:59:54 +0000 Subject: Avoid duplicating information. --- document/src/vespa/document/base/idstring.cpp | 1 - document/src/vespa/document/base/idstring.h | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'document') 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; -- cgit v1.2.3