Do less work
This commit is contained in:
@@ -744,31 +744,11 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
|
||||
for (auto *iter = right.n; iter != nullptr; iter = iter->parent) {
|
||||
rightPath.push_back(iter);
|
||||
}
|
||||
std::reverse(leftPath.begin(), leftPath.end());
|
||||
std::reverse(rightPath.begin(), rightPath.end());
|
||||
Node *lca = n;
|
||||
int longestCommonPrefixSize = 0;
|
||||
for (int i = 0, end = std::min<int>(leftPath.size(), rightPath.size());
|
||||
i < end; ++i, ++longestCommonPrefixSize) {
|
||||
if (leftPath[i] != rightPath[i]) {
|
||||
break;
|
||||
}
|
||||
lca = leftPath[i];
|
||||
}
|
||||
auto border = vector<Node *>(arena);
|
||||
for (int i = longestCommonPrefixSize; i < int(leftPath.size()); ++i) {
|
||||
border.push_back(leftPath[i]);
|
||||
}
|
||||
for (int i = longestCommonPrefixSize; i < int(rightPath.size()); ++i) {
|
||||
border.push_back(rightPath[i]);
|
||||
}
|
||||
|
||||
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
||||
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(begin).c_str(),
|
||||
getSearchPath(left.n).c_str());
|
||||
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(end).c_str(),
|
||||
getSearchPath(right.n).c_str());
|
||||
fprintf(stderr, "lca `%s'\n", getSearchPath(lca).c_str());
|
||||
#endif
|
||||
|
||||
if (left.n != nullptr && left.cmp != 0 &&
|
||||
@@ -783,15 +763,22 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO make it sublinear
|
||||
// TODO better data structure for pointer set. Also collect during first
|
||||
// traversal.
|
||||
for (auto *iter = nextPhysical(left.n); iter != right.n;) {
|
||||
assert(iter != lca);
|
||||
if (std::find(border.begin(), border.end(), iter) == border.end()) {
|
||||
const bool onLeftPath =
|
||||
std::find(leftPath.begin(), leftPath.end(), iter) != leftPath.end();
|
||||
const bool onRightPath =
|
||||
std::find(rightPath.begin(), rightPath.end(), iter) != rightPath.end();
|
||||
if (!onLeftPath && !onRightPath) {
|
||||
if (iter->maxVersion > readVersion) {
|
||||
return false;
|
||||
}
|
||||
iter = nextPhysicalSkipSubtree(iter);
|
||||
} else {
|
||||
if (onRightPath && iter->maxVersion <= readVersion) {
|
||||
return true;
|
||||
}
|
||||
if (iter->entryPresent &&
|
||||
std::max(iter->entry.pointVersion, iter->entry.rangeVersion) >
|
||||
readVersion) {
|
||||
|
Reference in New Issue
Block a user