Signed-off-by: Tomek Grabiec <[email protected]>
---
include/vm/radix-tree.h | 8 ++--
jit/cu-mapping.c | 6 ++--
test/vm/radix-tree-test.c | 20 ++++++------
vm/radix-tree.c | 71 ++++++++++++++++++++++++---------------------
4 files changed, 55 insertions(+), 50 deletions(-)
diff --git a/include/vm/radix-tree.h b/include/vm/radix-tree.h
index 18f1790..3f64c27 100644
--- a/include/vm/radix-tree.h
+++ b/include/vm/radix-tree.h
@@ -7,9 +7,9 @@ struct radix_tree *alloc_radix_tree(unsigned int bits_per_level,
unsigned int key_bits);
void free_radix_tree(struct radix_tree *tree);
-int tree_put(struct radix_tree *tree, unsigned long key, void *value);
-void tree_remove(struct radix_tree *tree, unsigned long key);
-void *tree_lookup(struct radix_tree *tree, unsigned long key);
-void *tree_lookup_preceeding(struct radix_tree *tree, unsigned long key);
+int radix_tree_insert(struct radix_tree *tree, unsigned long key, void *value);
+void radix_tree_remove(struct radix_tree *tree, unsigned long key);
+void *radix_tree_lookup(struct radix_tree *tree, unsigned long key);
+void *radix_tree_lookup_prev(struct radix_tree *tree, unsigned long key);
#endif /* _VM_RADIX_TREE */
diff --git a/jit/cu-mapping.c b/jit/cu-mapping.c
index 2209e10..87fb1c9 100644
--- a/jit/cu-mapping.c
+++ b/jit/cu-mapping.c
@@ -64,12 +64,12 @@ static unsigned long cu_key(struct compilation_unit *cu)
int add_cu_mapping(struct compilation_unit *cu)
{
- return tree_put(cu_map, cu_key(cu), cu);
+ return radix_tree_insert(cu_map, cu_key(cu), cu);
}
void remove_cu_mapping(struct compilation_unit *cu)
{
- tree_remove(cu_map, cu_key(cu));
+ radix_tree_remove(cu_map, cu_key(cu));
}
struct compilation_unit *get_cu_from_native_addr(unsigned long addr)
@@ -77,7 +77,7 @@ struct compilation_unit *get_cu_from_native_addr(unsigned
long addr)
struct compilation_unit *cu;
unsigned long method_addr;
- cu = tree_lookup_preceeding(cu_map, addr_key(addr));
+ cu = radix_tree_lookup_prev(cu_map, addr_key(addr));
if (cu == NULL)
return NULL;
diff --git a/test/vm/radix-tree-test.c b/test/vm/radix-tree-test.c
index b59b96f..db60c3c 100644
--- a/test/vm/radix-tree-test.c
+++ b/test/vm/radix-tree-test.c
@@ -6,7 +6,7 @@
#include <limits.h>
#include <vm/radix-tree.h>
-void test_tree_put_and_lookup()
+void test_tree_insert_and_lookup()
{
unsigned long key;
struct radix_tree *tree;
@@ -15,17 +15,17 @@ void test_tree_put_and_lookup()
tree = alloc_radix_tree(2, sizeof(key)*8);
key = 1;
- tree_put(tree, key, (void*)0xcafebabe);
- result = tree_lookup(tree, key);
+ radix_tree_insert(tree, key, (void*)0xcafebabe);
+ result = radix_tree_lookup(tree, key);
assert_ptr_equals((void*)0xcafebabe, result);
key = ULONG_MAX;
- tree_put(tree, key, (void*)0xdeadbeef);
- result = tree_lookup(tree, key);
+ radix_tree_insert(tree, key, (void*)0xdeadbeef);
+ result = radix_tree_lookup(tree, key);
assert_ptr_equals((void*)0xdeadbeef, result);
key = key - 1;
- result = tree_lookup_preceeding(tree, key);
+ result = radix_tree_lookup_prev(tree, key);
assert_ptr_equals((void*)0xcafebabe, result);
free_radix_tree(tree);
@@ -43,12 +43,12 @@ void test_tree_remove()
key = 0xdeadbeef;
value = (void*)0xcafebabe;
- tree_put(tree, key, value);
- result = tree_lookup(tree, key);
+ radix_tree_insert(tree, key, value);
+ result = radix_tree_lookup(tree, key);
assert_ptr_equals(value, result);
- tree_remove(tree, key);
- result = tree_lookup(tree, key);
+ radix_tree_remove(tree, key);
+ result = radix_tree_lookup(tree, key);
assert_ptr_equals(NULL, result);
free_radix_tree(tree);
diff --git a/vm/radix-tree.c b/vm/radix-tree.c
index 8e71f56..40b12e2 100644
--- a/vm/radix-tree.c
+++ b/vm/radix-tree.c
@@ -144,36 +144,39 @@ static void free_radix_tree_node(struct radix_tree *tree,
int i;
if (level < level_count(tree) - 1)
- for (i = 0; i < slot_count(tree); i++)
- if (node->slots[i] != NULL)
- free_radix_tree_node(tree, node->slots[i],
- level + 1);
+ for (i = 0; i < slot_count(tree); i++) {
+ if (node->slots[i] == NULL)
+ continue;
+
+ free_radix_tree_node(tree, node->slots[i], level + 1);
+ }
free(node);
}
void free_radix_tree(struct radix_tree *tree)
{
- free_radix_tree_node(tree, tree->root, 0);
- free(tree);
+ if (tree) {
+ free_radix_tree_node(tree, tree->root, 0);
+ free(tree);
+ }
}
-static void *tree_last(struct radix_tree *tree, struct radix_tree_node *node,
- int level)
+static void *radix_tree_last(struct radix_tree *tree,
+ struct radix_tree_node *node, int level)
{
int i;
while (level < level_count(tree)) {
-
for (i = slot_count(tree) - 1; i >= 0; i--)
- if (node->slots[i] != NULL) {
- node = node->slots[i];
- level++;
+ if (node->slots[i] != NULL)
break;
- }
if (i < 0)
return NULL;
+
+ node = node->slots[i];
+ level++;
}
return node;
@@ -188,8 +191,8 @@ static unsigned long get_index(struct radix_tree *tree,
unsigned long key,
}
static void *
-tree_previous(struct radix_tree *tree, struct radix_tree_node *node,
- unsigned long key, int level)
+radix_tree_previous(struct radix_tree *tree, struct radix_tree_node *node,
+ unsigned long key, int level)
{
int index;
@@ -205,19 +208,21 @@ tree_previous(struct radix_tree *tree, struct
radix_tree_node *node,
for (index = get_index(tree, key, level) - 1; index >= 0; index--)
if (node->slots[index] != NULL)
- return tree_last(tree, node->slots[index], level + 1);
+ return radix_tree_last(tree, node->slots[index],
+ level + 1);
- return tree_previous(tree, node->parent, key, level - 1);
+ return radix_tree_previous(tree, node->parent, key, level - 1);
}
/**
- * tree_put - put key->value mapping into the tree. Returns 0 upon success.
+ * radix_tree_insert - Insert key->value mapping into the tree.
+ * Returns 0 on success.
*
* @tree: a radix tree to put into.
* @key: the search key
* @value: the value to associate key with
*/
-int tree_put(struct radix_tree *tree, unsigned long key, void *value)
+int radix_tree_insert(struct radix_tree *tree, unsigned long key, void *value)
{
struct radix_tree_node *node = tree->root;
int i;
@@ -257,11 +262,11 @@ static void free_slot(struct radix_tree *tree, struct
radix_tree_node *node,
}
/**
- * tree_remove - remove mapping from tree.
+ * radix_tree_remove - remove mapping from tree.
* @tree: a radix tree to remove from.
* @key: a key to remove.
*/
-void tree_remove(struct radix_tree *tree, unsigned long key)
+void radix_tree_remove(struct radix_tree *tree, unsigned long key)
{
int i;
struct radix_tree_node *node = tree->root;
@@ -278,8 +283,8 @@ void tree_remove(struct radix_tree *tree, unsigned long key)
free_slot(tree, node, key, i);
}
-static void *__tree_lookup(struct radix_tree *tree, unsigned long key,
- bool try_preceeding)
+static void *__radix_tree_lookup(struct radix_tree *tree, unsigned long key,
+ bool try_previous)
{
int i;
struct radix_tree_node *node = tree->root;
@@ -288,8 +293,8 @@ static void *__tree_lookup(struct radix_tree *tree,
unsigned long key,
int index = get_index(tree, key, i);
if (node->slots[index] == NULL) {
- if (try_preceeding)
- return tree_previous(tree, node, key, i);
+ if (try_previous)
+ return radix_tree_previous(tree, node, key, i);
else
return NULL;
}
@@ -302,27 +307,26 @@ static void *__tree_lookup(struct radix_tree *tree,
unsigned long key,
/**
- * tree_lookup - get the value associated with @key. Returns NULL when no
+ * radix_tree_lookup - get the value associated with @key. Returns NULL when no
* mapping exists.
*
* @tree: a radix tree to lookup in.
* @key: a key which value should be abtained.
*/
-void *tree_lookup(struct radix_tree *tree, unsigned long key)
+void *radix_tree_lookup(struct radix_tree *tree, unsigned long key)
{
- return __tree_lookup(tree, key, false);
+ return __radix_tree_lookup(tree, key, false);
}
/**
- * tree_lookup_preceeding - get the value associated with @key or
- * the value associated with the preceeding key.
- * Returns NULL when no preceeding key exists.
+ * radix_tree_lookup_prev - get the value associated with @key or
+ * the value associated with the preceding key.
+ * Returns NULL when no preceding key exists.
*
* @tree: a radix tree to lookup in.
* @key: a key which value should be returned.
*/
-void *tree_lookup_preceeding(struct radix_tree *tree, unsigned long key)
+void *radix_tree_lookup_prev(struct radix_tree *tree, unsigned long key)
{
- return __tree_lookup(tree, key, true);
+ return __radix_tree_lookup(tree, key, true);
}
--
1.6.0.6
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel