mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-23 01:50:07 +03:00
gpu: nvgpu: utils: improve CCM for rbtree
This improves the code complexity of the rbtree function nvgpu_rbtree_unlink() by creating helper functions swap_in_new_child() and adopt_children(). This reduces the TCC metric to 9. JIRA NVGPU-4097 Change-Id: I2eb9ddf9a74478600874c71dab2b1267b5148b7b Signed-off-by: Philip Elcan <pelcan@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/2205845 Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com> Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com> Reviewed-by: Nicolas Benech <nbenech@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman <alexw@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
Alex Waterman
parent
5e0bf2bb7a
commit
b5f1135ba8
@@ -295,6 +295,35 @@ static void delete_fixup(struct nvgpu_rbtree_node **root,
|
||||
}
|
||||
}
|
||||
|
||||
static void swap_in_new_child(struct nvgpu_rbtree_node *old,
|
||||
struct nvgpu_rbtree_node *new,
|
||||
struct nvgpu_rbtree_node **root)
|
||||
{
|
||||
if (old->parent != NULL) {
|
||||
if (old == old->parent->left) {
|
||||
old->parent->left = new;
|
||||
} else {
|
||||
old->parent->right = new;
|
||||
}
|
||||
} else {
|
||||
*root = new;
|
||||
}
|
||||
}
|
||||
|
||||
static void adopt_children(struct nvgpu_rbtree_node *old,
|
||||
struct nvgpu_rbtree_node *new)
|
||||
{
|
||||
new->left = old->left;
|
||||
if (old->left != NULL) {
|
||||
old->left->parent = new;
|
||||
}
|
||||
|
||||
new->right = old->right;
|
||||
if (old->right != NULL) {
|
||||
old->right->parent = new;
|
||||
}
|
||||
}
|
||||
|
||||
void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
|
||||
struct nvgpu_rbtree_node **root)
|
||||
{
|
||||
@@ -330,16 +359,8 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
|
||||
if (x != NULL) {
|
||||
x->parent = parent_of_x;
|
||||
}
|
||||
|
||||
if (y->parent != NULL) {
|
||||
if (y == y->parent->left) {
|
||||
y->parent->left = x;
|
||||
} else {
|
||||
y->parent->right = x;
|
||||
}
|
||||
} else {
|
||||
*root = x;
|
||||
}
|
||||
/* update the parent's links */
|
||||
swap_in_new_child(y, x, root);
|
||||
|
||||
y_was_black = !y->is_red;
|
||||
if (y != z) {
|
||||
@@ -347,27 +368,11 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
|
||||
* the memory for z can be freed
|
||||
*/
|
||||
y->parent = z->parent;
|
||||
if (z->parent != NULL) {
|
||||
if (z == z->parent->left) {
|
||||
z->parent->left = y;
|
||||
} else {
|
||||
z->parent->right = y;
|
||||
}
|
||||
} else {
|
||||
*root = y;
|
||||
}
|
||||
swap_in_new_child(z, y, root);
|
||||
|
||||
y->is_red = z->is_red;
|
||||
|
||||
y->left = z->left;
|
||||
if (z->left != NULL) {
|
||||
z->left->parent = y;
|
||||
}
|
||||
|
||||
y->right = z->right;
|
||||
if (z->right != NULL) {
|
||||
z->right->parent = y;
|
||||
}
|
||||
adopt_children(z, y);
|
||||
|
||||
if (parent_of_x == z) {
|
||||
parent_of_x = y;
|
||||
|
||||
Reference in New Issue
Block a user