mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 07:40:42 +01:00
[poincare] Escape replace/removeChild when tree is alloc fail
This commit is contained in:
@@ -83,11 +83,7 @@ public:
|
||||
// Replace
|
||||
void replaceWithInPlace(TreeByReference t);
|
||||
void replaceChildInPlace(TreeByReference oldChild, TreeByReference newChild);
|
||||
void replaceChildAtIndexInPlace(int oldChildIndex, TreeByReference newChild) {
|
||||
assert(oldChildIndex >= 0 && oldChildIndex < numberOfChildren());
|
||||
TreeByReference oldChild = childAtIndex(oldChildIndex);
|
||||
replaceChildInPlace(oldChild, newChild);
|
||||
}
|
||||
void replaceChildAtIndexInPlace(int oldChildIndex, TreeByReference newChild);
|
||||
void replaceWithAllocationFailureInPlace(int currentNumberOfChildren);
|
||||
void replaceChildWithGhostInPlace(TreeByReference t);
|
||||
// Merge
|
||||
|
||||
@@ -86,6 +86,18 @@ void TreeByReference::replaceChildInPlace(TreeByReference oldChild, TreeByRefere
|
||||
oldChild.node()->release(oldChild.numberOfChildren());
|
||||
}
|
||||
|
||||
void TreeByReference::replaceChildAtIndexInPlace(int oldChildIndex, TreeByReference newChild) {
|
||||
if (oldChildIndex < 0 || oldChildIndex >= numberOfChildren()) {
|
||||
/* The only case where the index might be out of range is when a tree has
|
||||
* become an allocation failure, in which case we need to escape the invalid
|
||||
* child removal. */
|
||||
assert(isAllocationFailure());
|
||||
return;
|
||||
}
|
||||
TreeByReference oldChild = childAtIndex(oldChildIndex);
|
||||
replaceChildInPlace(oldChild, newChild);
|
||||
}
|
||||
|
||||
void TreeByReference::replaceWithAllocationFailureInPlace(int currentNumberOfChildren) {
|
||||
if (isAllocationFailure()) {
|
||||
return;
|
||||
@@ -219,7 +231,13 @@ void TreeByReference::addChildAtIndexInPlace(TreeByReference t, int index, int c
|
||||
|
||||
void TreeByReference::removeChildAtIndexInPlace(int i) {
|
||||
assert(!isUninitialized());
|
||||
assert(i >= 0 && i < numberOfChildren());
|
||||
if (i < 0 || i >= numberOfChildren()) {
|
||||
/* The only case where the index might be out of range is when a tree has
|
||||
* become an allocation failure, in which case we need to escape the invalid
|
||||
* child removal. */
|
||||
assert(isAllocationFailure());
|
||||
return;
|
||||
}
|
||||
TreeByReference t = childAtIndex(i);
|
||||
removeChildInPlace(t, t.numberOfChildren());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user