Add Type template parameter to maybeDownsize to avoid branch
All checks were successful
Tests / Clang total: 932, passed: 932
Clang |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |3|0|3|0|:zzz:
Tests / Release [gcc] total: 932, passed: 932
Tests / Release [gcc,aarch64] total: 931, passed: 931
Tests / Coverage total: 930, passed: 930
weaselab/conflict-set/pipeline/head This commit looks good

This commit is contained in:
2024-03-15 18:01:47 -07:00
parent 9f5a68e2c0
commit 303b368fc5

View File

@@ -1086,7 +1086,7 @@ void maybeDecreaseCapacity(Node *&self, NodeAllocators *allocators,
allocators, impl);
}
// TODO fuse into erase child so we don't need to repeat branches on type
template <Type kType>
void maybeDownsize(Node *self, NodeAllocators *allocators,
ConflictSet::Impl *impl, Node *&dontInvalidate) {
@@ -1094,7 +1094,9 @@ void maybeDownsize(Node *self, NodeAllocators *allocators,
fprintf(stderr, "maybeDownsize: %s\n", getSearchPathPrintable(self).c_str());
#endif
switch (self->getType()) {
assert(self->getType() == kType);
static_assert(kType != Type_Node0);
switch (kType) {
case Type_Node0:
__builtin_unreachable(); // GCOVR_EXCL_LINE
case Type_Node3: {
@@ -1198,7 +1200,24 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
if (self->numChildren != 0) {
const bool update = result == dontInvalidate;
maybeDownsize(self, allocators, impl, result);
switch (self->getType()) {
case Type_Node0:
__builtin_unreachable(); // GCOVR_EXCL_LINE
case Type_Node3:
maybeDownsize<Type_Node3>(self, allocators, impl, result);
break;
case Type_Node16:
maybeDownsize<Type_Node16>(self, allocators, impl, result);
break;
case Type_Node48:
maybeDownsize<Type_Node48>(self, allocators, impl, result);
break;
case Type_Node256:
maybeDownsize<Type_Node256>(self, allocators, impl, result);
break;
default: // GCOVR_EXCL_LINE
__builtin_unreachable(); // GCOVR_EXCL_LINE
}
if (update) {
dontInvalidate = result;
}
@@ -1238,6 +1257,18 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
memmove(parent3->children + nodeIndex, parent3->children + nodeIndex + 1,
sizeof(parent3->children[0]) *
(parent->numChildren - (nodeIndex + 1)));
--parent->numChildren;
if (parent->numChildren == 0 && !parent->entryPresent &&
parent->parent != nullptr) {
return erase(parent, allocators, impl, dontInvalidate);
} else {
const bool update = result == dontInvalidate;
maybeDownsize<Type_Node3>(parent, allocators, impl, result);
if (update) {
dontInvalidate = result;
}
}
} break;
case Type_Node16: {
auto *parent16 = static_cast<Node16 *>(parent);
@@ -1249,6 +1280,18 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
memmove(parent16->children + nodeIndex, parent16->children + nodeIndex + 1,
sizeof(parent16->children[0]) *
(parent->numChildren - (nodeIndex + 1)));
--parent->numChildren;
if (parent->numChildren == 0 && !parent->entryPresent &&
parent->parent != nullptr) {
return erase(parent, allocators, impl, dontInvalidate);
} else {
const bool update = result == dontInvalidate;
maybeDownsize<Type_Node16>(parent, allocators, impl, result);
if (update) {
dontInvalidate = result;
}
}
} break;
case Type_Node48: {
auto *parent48 = static_cast<Node48 *>(parent);
@@ -1264,15 +1307,6 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
parent48->index[parent48->children[toRemoveChildrenIndex]
.child->parentsIndex] = toRemoveChildrenIndex;
}
} break;
case Type_Node256: {
auto *parent256 = static_cast<Node256 *>(parent);
parent256->bitSet.reset(parentsIndex);
parent256->children[parentsIndex].child = nullptr;
} break;
default: // GCOVR_EXCL_LINE
__builtin_unreachable(); // GCOVR_EXCL_LINE
}
--parent->numChildren;
if (parent->numChildren == 0 && !parent->entryPresent &&
@@ -1280,11 +1314,33 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
return erase(parent, allocators, impl, dontInvalidate);
} else {
const bool update = result == dontInvalidate;
maybeDownsize(parent, allocators, impl, result);
maybeDownsize<Type_Node48>(parent, allocators, impl, result);
if (update) {
dontInvalidate = result;
}
}
} break;
case Type_Node256: {
auto *parent256 = static_cast<Node256 *>(parent);
parent256->bitSet.reset(parentsIndex);
parent256->children[parentsIndex].child = nullptr;
--parent->numChildren;
if (parent->numChildren == 0 && !parent->entryPresent &&
parent->parent != nullptr) {
return erase(parent, allocators, impl, dontInvalidate);
} else {
const bool update = result == dontInvalidate;
maybeDownsize<Type_Node256>(parent, allocators, impl, result);
if (update) {
dontInvalidate = result;
}
}
} break;
default: // GCOVR_EXCL_LINE
__builtin_unreachable(); // GCOVR_EXCL_LINE
}
return result;
}