From: Dana Jansens Date: Mon, 2 Nov 2009 21:47:44 +0000 (-0500) Subject: Use a constant for the size of the GTreeNode's pointer version table, based on the... X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=b64087e49bf7be5121f3b3b2ebfa9d2ab1e64f9a;p=dana%2Fcg-glib.git Use a constant for the size of the GTreeNode's pointer version table, based on the maximum in-degree for a node. --- diff --git a/glib/gtree.c b/glib/gtree.c index a58cea5a..65e00fc0 100644 --- a/glib/gtree.c +++ b/glib/gtree.c @@ -35,8 +35,12 @@ #undef G_TREE_DEBUG -#define MAX_OUT_DEGREE 3 #define MAX_IN_DEGREE 3 +#define TABLE_SIZE (MAX_IN_DEGREE+1) /* This is the minimum size required so + that you only have a constant number of + nodes fill up their tables and + require a new node to be created at + a time. */ typedef struct _GTreeRootVersion GTreeRootVersion; typedef struct _GTreeNodeVersion GTreeNodeVersion; @@ -154,7 +158,7 @@ g_tree_node_new (GTree *tree, so that we don't use a lot more memory when persistence isn't even being used */ node->v = g_slice_alloc(sizeof(GTreeNodeVersion) * - (tree->version == 0 ? 1 : MAX_IN_DEGREE + 1)); + (tree->version == 0 ? 1 : TABLE_SIZE)); node->nv = 1; node->v[0].version = tree->version; @@ -296,7 +300,7 @@ g_tree_node_find_version(GTreeNode *node, if (v[0].version <= version) return v; - /* there are at most MAX_IN_DEGREE+1 things to look through, which is small, + /* there are at most TABLE_SIZE things to look through, which is small, so just scan through them from largest version to smallest */ for (n = v+(nv-1); n != v; --n) if (n->version <= version) @@ -402,7 +406,7 @@ g_tree_node_remove (GTree *tree, GTreeNode *node) tree->value_destroy_func (node->data->value); g_slice_free1 (sizeof(GTreeNodeVersion) * - (node->version(NOW) == 0 ? 1 : MAX_IN_DEGREE + 1), + (node->version(NOW) == 0 ? 1 : TABLE_SIZE), node->v); if (--node->data->ref_count == 0) { @@ -557,10 +561,10 @@ g_tree_node_add_version (GTree *tree, if (node->version(NOW) == tree->version) return node; /* if we filled the node's pointer table and need to make a new GTreeNode */ - else if (node->version(NOW) == 0 || node->nv >= MAX_IN_DEGREE+1) + else if (node->version(NOW) == 0 || node->nv >= TABLE_SIZE) { GTreeNode *newnode = g_slice_new(GTreeNode); - newnode->v = g_slice_alloc(sizeof(GTreeNodeVersion) * (MAX_IN_DEGREE+1)); + newnode->v = g_slice_alloc(sizeof(GTreeNodeVersion) * TABLE_SIZE); newnode->data = node->data; newnode->data->ref_count++; newnode->v[0] = node->v[0]; /* copy the latest version to here */ @@ -1091,7 +1095,7 @@ g_tree_remove_internal (GTree *tree, } g_slice_free1 (sizeof(GTreeNodeVersion) * - (node->version(NOW) == 0 ? 1 : MAX_IN_DEGREE + 1), + (node->version(NOW) == 0 ? 1 : TABLE_SIZE), node->v); g_slice_free (GTreeNode, node); }