Use a constant for the size of the GTreeNode's pointer version table, based on the...
authorDana Jansens <danakj@orodu.net>
Mon, 2 Nov 2009 21:47:44 +0000 (16:47 -0500)
committerDana Jansens <danakj@orodu.net>
Thu, 12 Nov 2009 22:21:04 +0000 (17:21 -0500)
glib/gtree.c

index a58cea5ac083dcab774dc66530ccdb50242d2a75..65e00fc0753e1b3c348eb68868144f0270a96853 100644 (file)
 
 #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);
     }