Use unsigned compare trick to check in bounds
This commit is contained in:
@@ -1675,6 +1675,12 @@ bool checkMaxBetweenExclusive(Node *n, int begin, int end,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [begin, end) is now the half-open interval of children we're interested in.
|
||||||
|
|
||||||
|
const unsigned shiftUpperBound = end - begin;
|
||||||
|
const unsigned shiftAmount = begin;
|
||||||
|
auto inBounds = [&](unsigned c) { return c - shiftAmount < shiftUpperBound; };
|
||||||
|
|
||||||
switch (n->getType()) {
|
switch (n->getType()) {
|
||||||
case Type_Node0: // GCOVR_EXCL_LINE
|
case Type_Node0: // GCOVR_EXCL_LINE
|
||||||
// We would have returned above, after not finding a child
|
// We would have returned above, after not finding a child
|
||||||
@@ -1684,7 +1690,7 @@ bool checkMaxBetweenExclusive(Node *n, int begin, int end,
|
|||||||
bool result = true;
|
bool result = true;
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
result &= !((self->children[i].childMaxVersion > readVersion) &
|
result &= !((self->children[i].childMaxVersion > readVersion) &
|
||||||
(begin <= self->index[i]) & (self->index[i] < end));
|
inBounds(self->index[i]));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} break;
|
} break;
|
||||||
@@ -1693,7 +1699,7 @@ bool checkMaxBetweenExclusive(Node *n, int begin, int end,
|
|||||||
bool result = true;
|
bool result = true;
|
||||||
for (int i = 0; i < 16; ++i) {
|
for (int i = 0; i < 16; ++i) {
|
||||||
result &= !((self->children[i].childMaxVersion > readVersion) &
|
result &= !((self->children[i].childMaxVersion > readVersion) &
|
||||||
(begin <= self->index[i]) & (self->index[i] < end));
|
inBounds(self->index[i]));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} break;
|
} break;
|
||||||
@@ -1704,9 +1710,8 @@ bool checkMaxBetweenExclusive(Node *n, int begin, int end,
|
|||||||
assume(self->numChildren <= Node48::kMaxNodes);
|
assume(self->numChildren <= Node48::kMaxNodes);
|
||||||
for (int i = 0; i < self->numChildren; ++i) {
|
for (int i = 0; i < self->numChildren; ++i) {
|
||||||
assert(self->index[self->reverseIndex[i]] == i);
|
assert(self->index[self->reverseIndex[i]] == i);
|
||||||
conflict[i] = (begin <= self->reverseIndex[i]) &
|
conflict[i] = (self->children[i].childMaxVersion > readVersion) &
|
||||||
(self->reverseIndex[i] < end) &
|
inBounds(self->reverseIndex[i]);
|
||||||
(self->children[i].childMaxVersion > readVersion);
|
|
||||||
}
|
}
|
||||||
bool result = true;
|
bool result = true;
|
||||||
for (auto c : conflict) {
|
for (auto c : conflict) {
|
||||||
@@ -1721,8 +1726,8 @@ bool checkMaxBetweenExclusive(Node *n, int begin, int end,
|
|||||||
bool result = true;
|
bool result = true;
|
||||||
for (int i = 0; i < Node256::kMaxOfMaxPageSize; ++i) {
|
for (int i = 0; i < Node256::kMaxOfMaxPageSize; ++i) {
|
||||||
int j = (begin & ~(Node256::kMaxOfMaxPageSize - 1)) + i;
|
int j = (begin & ~(Node256::kMaxOfMaxPageSize - 1)) + i;
|
||||||
result &= !((self->children[j].childMaxVersion > readVersion) &
|
result &=
|
||||||
(begin <= j) & (j < end));
|
!((self->children[j].childMaxVersion > readVersion) & inBounds(j));
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user