Allow reusing leaf nodes unless the next leaf has changes

This commit is contained in:
Max Brunsfeld 2018-03-07 16:13:34 -08:00
parent 53cd89c614
commit e927d02f43
3 changed files with 48 additions and 18 deletions

View file

@ -28,10 +28,22 @@ static inline void reusable_node_pop(ReusableNode *self) {
}
}
static inline void reusable_node_pop_leaf(ReusableNode *self) {
while (self->tree->child_count > 0)
self->tree = self->tree->children[0];
reusable_node_pop(self);
static inline ReusableNode reusable_node_after_leaf(const ReusableNode *self) {
ReusableNode result = *self;
while (result.tree->child_count > 0)
result.tree = result.tree->children[0];
reusable_node_pop(&result);
return result;
}
static inline bool reusable_node_has_leading_changes(const ReusableNode *self) {
Tree *tree = self->tree;
while (tree->has_changes) {
if (tree->child_count == 0) return false;
tree = tree->children[0];
if (tree->size.bytes == 0) return false;
}
return true;
}
static inline bool reusable_node_breakdown(ReusableNode *self) {