diff --git a/ConflictSet.cpp b/ConflictSet.cpp index e29094a..dc8521b 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -1408,9 +1408,9 @@ bool checkRangeRead(Node *n, std::span begin, // setting 'entry' fields and `maxVersion` on the result, which may have // !entryPresent. The search path of the result's parent will have // `maxVersion` at least `writeVersion` as a postcondition. +template [[nodiscard]] Node *insert(Node **self_, std::span key, - int64_t writeVersion, bool begin, - NodeAllocators *allocators) { + int64_t writeVersion, NodeAllocators *allocators) { for (;;) { auto &self = *self_; // Handle an existing partial key @@ -1445,7 +1445,7 @@ bool checkRangeRead(Node *n, std::span begin, key = key.subspan(self->partialKeyLen, key.size() - self->partialKeyLen); } - if (begin) { + if constexpr (kBegin) { self->maxVersion = std::max(self->maxVersion, writeVersion); } @@ -1453,7 +1453,7 @@ bool checkRangeRead(Node *n, std::span begin, return self; } - if (!begin) { + if constexpr (!kBegin) { self->maxVersion = std::max(self->maxVersion, writeVersion); } @@ -1463,7 +1463,7 @@ bool checkRangeRead(Node *n, std::span begin, child->parent = self; child->parentsIndex = key.front(); child->maxVersion = - begin ? writeVersion : std::numeric_limits::lowest(); + kBegin ? writeVersion : std::numeric_limits::lowest(); } self_ = &child; @@ -1492,7 +1492,7 @@ void destroyTree(Node *root) { void addPointWrite(Node *&root, int64_t oldestVersion, std::span key, int64_t writeVersion, NodeAllocators *allocators) { - auto *n = insert(&root, key, writeVersion, true, allocators); + auto *n = insert(&root, key, writeVersion, allocators); if (!n->entryPresent) { auto *p = nextLogical(n); n->entryPresent = true; @@ -1550,7 +1550,7 @@ void addWriteRange(Node *&root, int64_t oldestVersion, begin = begin.subspan(consumed, begin.size() - consumed); end = end.subspan(consumed, end.size() - consumed); - auto *beginNode = insert(useAsRoot, begin, writeVersion, true, allocators); + auto *beginNode = insert(useAsRoot, begin, writeVersion, allocators); const bool insertedBegin = !std::exchange(beginNode->entryPresent, true); @@ -1565,7 +1565,7 @@ void addWriteRange(Node *&root, int64_t oldestVersion, beginNode->entry.pointVersion = std::max(beginNode->entry.pointVersion, writeVersion); - auto *endNode = insert(useAsRoot, end, writeVersion, false, allocators); + auto *endNode = insert(useAsRoot, end, writeVersion, allocators); const bool insertedEnd = !std::exchange(endNode->entryPresent, true); @@ -1580,7 +1580,7 @@ void addWriteRange(Node *&root, int64_t oldestVersion, if (insertedEnd) { // beginNode may have been invalidated - beginNode = insert(useAsRoot, begin, writeVersion, true, allocators); + beginNode = insert(useAsRoot, begin, writeVersion, allocators); } for (beginNode = nextLogical(beginNode); beginNode != endNode;) {