Skip to content

Commit

Permalink
ICU-22934 Simplfied
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankYFTang committed Oct 10, 2024
1 parent e735fe0 commit e86eab7
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions icu4c/source/common/rbbinode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ RBBINode *RBBINode::cloneTree(UErrorCode &status, int depth) {
} else {
n = new RBBINode(*this, status);
// Check for null pointer.
if (n == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(status)) {
return nullptr;
}
Expand Down Expand Up @@ -280,20 +277,33 @@ RBBINode *RBBINode::flattenVariables(UErrorCode& status, int depth) {
}
if (fType == varRef) {
RBBINode *retNode = fLeftChild->cloneTree(status, depth+1);
if (retNode != nullptr) {
retNode->fRuleRoot = this->fRuleRoot;
retNode->fChainIn = this->fChainIn;
if (U_FAILURE(status)) {
return this;
}
retNode->fRuleRoot = this->fRuleRoot;
retNode->fChainIn = this->fChainIn;
delete this; // TODO: undefined behavior. Fix.
return retNode;
}

if (fLeftChild != nullptr) {
fLeftChild = fLeftChild->flattenVariables(status, depth+1);
if (fLeftChild == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(status)) {
return this;
}
fLeftChild->fParent = this;
}
if (fRightChild != nullptr) {
fRightChild = fRightChild->flattenVariables(status, depth+1);
if (fRightChild == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(status)) {
return this;
}
fRightChild->fParent = this;
}
return this;
Expand Down Expand Up @@ -326,9 +336,11 @@ void RBBINode::flattenSets(UErrorCode &status, int depth) {
RBBINode *usetNode = setRefNode->fLeftChild;
RBBINode *replTree = usetNode->fLeftChild;
fLeftChild = replTree->cloneTree(status, depth+1);
if (U_SUCCESS(status)) {
fLeftChild->fParent = this;
if (U_FAILURE(status)) {
delete setRefNode;
return;
}
fLeftChild->fParent = this;
delete setRefNode;
} else {
fLeftChild->flattenSets(status, depth+1);
Expand All @@ -341,9 +353,11 @@ void RBBINode::flattenSets(UErrorCode &status, int depth) {
RBBINode *usetNode = setRefNode->fLeftChild;
RBBINode *replTree = usetNode->fLeftChild;
fRightChild = replTree->cloneTree(status, depth+1);
if (U_SUCCESS(status)) {
fRightChild->fParent = this;
if (U_FAILURE(status)) {
delete setRefNode;
return;
}
fRightChild->fParent = this;
delete setRefNode;
} else {
fRightChild->flattenSets(status, depth+1);
Expand Down

0 comments on commit e86eab7

Please sign in to comment.