summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2017-06-21 14:36:29 +0200
committerSergei Golubchik <serg@mariadb.org>2019-04-24 16:06:54 +0200
commit6cc19078ba7f2db521d44a3b8b9f0d5ea135625c (patch)
tree87bbfdccbd5da40d0c9887bd77c9ad13a5653f38 /mysys
parentbed1ede197cecca633023bf19248533fae085130 (diff)
downloadmariadb-git-6cc19078ba7f2db521d44a3b8b9f0d5ea135625c.tar.gz
cleanup: make TREE copyable
move per-object TREE::null_element to be one global static null_element.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/tree.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/mysys/tree.c b/mysys/tree.c
index 5eaeb30037d..9e69ed9a4db 100644
--- a/mysys/tree.c
+++ b/mysys/tree.c
@@ -77,6 +77,7 @@ static void rb_insert(TREE *tree,TREE_ELEMENT ***parent,
TREE_ELEMENT *leaf);
static void rb_delete_fixup(TREE *tree,TREE_ELEMENT ***parent);
+static TREE_ELEMENT null_element= { NULL, NULL, 0, BLACK };
/* The actual code for handling binary trees */
@@ -95,8 +96,7 @@ void init_tree(TREE *tree, size_t default_alloc_size, size_t memory_limit,
if (default_alloc_size < DEFAULT_ALLOC_SIZE)
default_alloc_size= DEFAULT_ALLOC_SIZE;
default_alloc_size= MY_ALIGN(default_alloc_size, DEFAULT_ALIGN_SIZE);
- bzero((uchar*) &tree->null_element,sizeof(tree->null_element));
- tree->root= &tree->null_element;
+ tree->root= &null_element;
tree->compare=compare;
tree->size_of_element= size > 0 ? (uint) size : 0;
tree->memory_limit=memory_limit;
@@ -104,8 +104,6 @@ void init_tree(TREE *tree, size_t default_alloc_size, size_t memory_limit,
tree->allocated=0;
tree->elements_in_tree=0;
tree->custom_arg = custom_arg;
- tree->null_element.colour=BLACK;
- tree->null_element.left=tree->null_element.right=0;
tree->my_flags= my_flags;
tree->flag= 0;
if (!free_element && size >= 0 &&
@@ -158,7 +156,7 @@ static void free_tree(TREE *tree, myf free_flags)
free_root(&tree->mem_root, free_flags);
}
}
- tree->root= &tree->null_element;
+ tree->root= &null_element;
tree->elements_in_tree=0;
tree->allocated=0;
@@ -179,7 +177,7 @@ void reset_tree(TREE* tree)
static void delete_tree_element(TREE *tree, TREE_ELEMENT *element)
{
- if (element != &tree->null_element)
+ if (element != &null_element)
{
delete_tree_element(tree,element->left);
if (tree->free)
@@ -209,7 +207,7 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,
*parent = &tree->root; element= tree->root;
for (;;)
{
- if (element == &tree->null_element ||
+ if (element == &null_element ||
(cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element),
key)) == 0)
break;
@@ -222,7 +220,7 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,
*++parent = &element->left; element= element->left;
}
}
- if (element == &tree->null_element)
+ if (element == &null_element)
{
uint alloc_size;
if (tree->flag & TREE_ONLY_DUPS)
@@ -246,7 +244,7 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,
if (!element)
return(NULL);
**parent=element;
- element->left=element->right= &tree->null_element;
+ element->left=element->right= &null_element;
if (!tree->offset_to_key)
{
if (key_size == sizeof(void*)) /* no length, save pointer */
@@ -288,7 +286,7 @@ int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg)
*parent= &tree->root; element= tree->root;
for (;;)
{
- if (element == &tree->null_element)
+ if (element == &null_element)
return 1; /* Was not in tree */
if ((cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element),
key)) == 0)
@@ -302,12 +300,12 @@ int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg)
*++parent = &element->left; element= element->left;
}
}
- if (element->left == &tree->null_element)
+ if (element->left == &null_element)
{
(**parent)=element->right;
remove_colour= element->colour;
}
- else if (element->right == &tree->null_element)
+ else if (element->right == &null_element)
{
(**parent)=element->left;
remove_colour= element->colour;
@@ -316,7 +314,7 @@ int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg)
{
org_parent= parent;
*++parent= &element->right; nod= element->right;
- while (nod->left != &tree->null_element)
+ while (nod->left != &null_element)
{
*++parent= &nod->left; nod= nod->left;
}
@@ -346,7 +344,7 @@ void *tree_search(TREE *tree, void *key, void *custom_arg)
for (;;)
{
- if (element == &tree->null_element)
+ if (element == &null_element)
return (void*) 0;
if ((cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element),
key)) == 0)
@@ -371,8 +369,8 @@ void *tree_search_key(TREE *tree, const void *key,
TODO: support for HA_READ_KEY_OR_PREV, HA_READ_PREFIX flags if needed.
*/
- *parents = &tree->null_element;
- while (element != &tree->null_element)
+ *parents = &null_element;
+ while (element != &null_element)
{
*++parents= element;
if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element),
@@ -443,14 +441,14 @@ void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents,
{
TREE_ELEMENT *element= tree->root;
- *parents= &tree->null_element;
- while (element != &tree->null_element)
+ *parents= &null_element;
+ while (element != &null_element)
{
*++parents= element;
element= ELEMENT_CHILD(element, child_offs);
}
*last_pos= parents;
- return **last_pos != &tree->null_element ?
+ return **last_pos != &null_element ?
ELEMENT_KEY(tree, **last_pos) : NULL;
}
@@ -459,11 +457,11 @@ void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
{
TREE_ELEMENT *x= **last_pos;
- if (ELEMENT_CHILD(x, r_offs) != &tree->null_element)
+ if (ELEMENT_CHILD(x, r_offs) != &null_element)
{
x= ELEMENT_CHILD(x, r_offs);
*++*last_pos= x;
- while (ELEMENT_CHILD(x, l_offs) != &tree->null_element)
+ while (ELEMENT_CHILD(x, l_offs) != &null_element)
{
x= ELEMENT_CHILD(x, l_offs);
*++*last_pos= x;
@@ -473,12 +471,12 @@ void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
else
{
TREE_ELEMENT *y= *--*last_pos;
- while (y != &tree->null_element && x == ELEMENT_CHILD(y, r_offs))
+ while (y != &null_element && x == ELEMENT_CHILD(y, r_offs))
{
x= y;
y= *--*last_pos;
}
- return y == &tree->null_element ? NULL : ELEMENT_KEY(tree, y);
+ return y == &null_element ? NULL : ELEMENT_KEY(tree, y);
}
}
@@ -494,7 +492,7 @@ ha_rows tree_record_pos(TREE *tree, const void *key,
double left= 1;
double right= tree->elements_in_tree;
- while (element != &tree->null_element)
+ while (element != &null_element)
{
if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element),
key)) == 0)