mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1402284 - Make RedBlackTree::{Insert,Remove} work when the type has a constructor. r=njn
RedBlackTree::{Insert,Remove} allocate an object on the stack for its RedBlackTreeNode, and that shouldn't have side effects if the type happens to have a constructor. This will allow to add constructors to some of the mozjemalloc types. --HG-- extra : rebase_source : 14dbb7d73c86921701d83156186df5d645530dda
This commit is contained in:
parent
dc259d83a8
commit
6d94984475
@ -67,6 +67,7 @@
|
||||
#ifndef RB_H_
|
||||
#define RB_H_
|
||||
|
||||
#include "mozilla/Alignment.h"
|
||||
#include "Utils.h"
|
||||
|
||||
enum NodeColor
|
||||
@ -327,14 +328,16 @@ private:
|
||||
|
||||
void Insert(TreeNode* aNode)
|
||||
{
|
||||
TreeNode rbp_i_s;
|
||||
// rbp_i_s is only used as a placeholder for its RedBlackTreeNode. Use
|
||||
// AlignedStorage2 to avoid running the TreeNode base class constructor.
|
||||
mozilla::AlignedStorage2<TreeNode> rbp_i_s;
|
||||
TreeNode *rbp_i_g, *rbp_i_p, *rbp_i_c, *rbp_i_t, *rbp_i_u;
|
||||
int rbp_i_cmp = 0;
|
||||
rbp_i_g = nullptr;
|
||||
rbp_i_s.SetLeft(mRoot);
|
||||
rbp_i_s.SetRight(nullptr);
|
||||
rbp_i_s.SetColor(NodeColor::Black);
|
||||
rbp_i_p = &rbp_i_s;
|
||||
rbp_i_p = rbp_i_s.addr();
|
||||
rbp_i_p->SetLeft(mRoot);
|
||||
rbp_i_p->SetRight(nullptr);
|
||||
rbp_i_p->SetColor(NodeColor::Black);
|
||||
rbp_i_c = mRoot;
|
||||
/* Iteratively search down the tree for the insertion point,
|
||||
* splitting 4-nodes as they are encountered. At the end of each
|
||||
@ -405,19 +408,21 @@ private:
|
||||
rbp_i_p->SetLeft(aNode);
|
||||
}
|
||||
/* Update the root and make sure that it is black. */
|
||||
mRoot = rbp_i_s.Left();
|
||||
mRoot = rbp_i_s.addr()->Left();
|
||||
mRoot->SetColor(NodeColor::Black);
|
||||
}
|
||||
|
||||
void Remove(TreeNode* aNode)
|
||||
{
|
||||
TreeNode rbp_r_s;
|
||||
// rbp_r_s is only used as a placeholder for its RedBlackTreeNode. Use
|
||||
// AlignedStorage2 to avoid running the TreeNode base class constructor.
|
||||
mozilla::AlignedStorage2<TreeNode> rbp_r_s;
|
||||
TreeNode *rbp_r_p, *rbp_r_c, *rbp_r_xp, *rbp_r_t, *rbp_r_u;
|
||||
int rbp_r_cmp;
|
||||
rbp_r_s.SetLeft(mRoot);
|
||||
rbp_r_s.SetRight(nullptr);
|
||||
rbp_r_s.SetColor(NodeColor::Black);
|
||||
rbp_r_p = &rbp_r_s;
|
||||
rbp_r_p = rbp_r_s.addr();
|
||||
rbp_r_p->SetLeft(mRoot);
|
||||
rbp_r_p->SetRight(nullptr);
|
||||
rbp_r_p->SetColor(NodeColor::Black);
|
||||
rbp_r_c = mRoot;
|
||||
rbp_r_xp = nullptr;
|
||||
/* Iterate down the tree, but always transform 2-nodes to 3- or
|
||||
@ -577,7 +582,7 @@ private:
|
||||
}
|
||||
}
|
||||
/* Update root. */
|
||||
mRoot = rbp_r_s.Left();
|
||||
mRoot = rbp_r_s.addr()->Left();
|
||||
}
|
||||
|
||||
TreeNode* RotateLeft(TreeNode* aNode)
|
||||
|
Loading…
Reference in New Issue
Block a user