summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-04-06 12:40:28 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-04-06 12:40:28 +0000
commitd9529d4ce9056eaa5f184d26faec5d217a985812 (patch)
tree491f766ecb06263e9ca117c71909e3422b880707 /vespalib
parent6f9f476072586b51791a9f8320baebd7191dbfdc (diff)
Separate invalidation and destruction.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/stllike/hashtable.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/vespalib/src/vespa/vespalib/stllike/hashtable.h b/vespalib/src/vespa/vespalib/stllike/hashtable.h
index e96ef7d9175..8a5b65cd591 100644
--- a/vespalib/src/vespa/vespalib/stllike/hashtable.h
+++ b/vespalib/src/vespa/vespalib/stllike/hashtable.h
@@ -125,6 +125,8 @@ public:
if (rhs.valid()) {
new (_node) V(std::move(rhs.getValue()));
_next = rhs._next;
+ } else {
+ _next = invalid;
}
return *this;
}
@@ -140,15 +142,13 @@ public:
if (rhs.valid()) {
new (_node) V(rhs.getValue());
_next = rhs._next;
+ } else {
+ _next = invalid;
}
return *this;
}
~hash_node() {
- if (!can_skip_destruction<V>::value) {
- if (valid()) {
- getValue().~V();
- }
- }
+ destruct();
}
bool operator == (const hash_node & rhs) const {
return (_next == rhs._next) && (!valid() || (getValue() == rhs.getValue()));
@@ -157,17 +157,19 @@ public:
const V & getValue() const { return *reinterpret_cast<const V *>(_node); }
next_t getNext() const { return _next; }
void setNext(next_t next) { _next = next; }
- void invalidate() { destruct(); }
+ void invalidate() {
+ destruct();
+ _next = invalid;
+ }
void terminate() { _next = npos; }
bool valid() const { return _next != invalid; }
bool hasNext() const { return valid() && (_next != npos); }
private:
void destruct() {
- if (valid()) {
- if (!can_skip_destruction<V>::value) {
+ if (!can_skip_destruction<V>::value) {
+ if (valid()) {
getValue().~V();
}
- _next = invalid;
}
}
char _node[sizeof(V)] alignas(V);