Don't prepend new versions into the versioned-pointer arrays, so that new ones can...
authorDana Jansens <danakj@orodu.net>
Fri, 30 Oct 2009 13:33:07 +0000 (09:33 -0400)
committerDana Jansens <danakj@orodu.net>
Thu, 12 Nov 2009 21:54:04 +0000 (16:54 -0500)
glib/gtree.c

index 894ac6972db5e9a4a8f9acd9751d9507704a782e..c11a6a4e40263262aae3c79ac2ca7237bfce0e44 100644 (file)
@@ -51,7 +51,10 @@ struct _GTreeRoot
 
 struct _GTree
 {
-  GTreeRoot        *roots;
+  GTreeRoot        *roots; /* versioned root nodes of the tree.  roots[0] is
+                              the highest (latest) version.  then
+                              roots[1]..roots[nroots-1] are
+                              older versions in ascending order */
   guint             nroots;
   GCompareDataFunc  key_compare;
   GDestroyNotify    key_destroy_func;
@@ -86,9 +89,9 @@ struct _GTreeNodeData
 struct _GTreeNode
 {
   GTreeNodeData    *data; /* the node's permanent data */
-  GTreeNodeVersion *v;    /* versions of pointers for the node, new versions
-                           * are prepended onto the array so v[0] is the newest
-                           */
+  GTreeNodeVersion *v;    /* versions of pointers for the node.  v[0] is the
+                             highest (latest) version.  then v[1]..v[nv-1] are
+                             older versions in ascending order */
   guint             nv;   /* number of versions stored in this node */
 };
 
@@ -172,17 +175,12 @@ g_tree_root_next_version (GTree *tree)
 
   if (tree->rootversion(NOW) < tree->version)
     {
-      int i;
-
-      /* prepend a new version to the root */
+      /* add a new version of the root */
       tree->nroots++;
       tree->roots = g_renew(GTreeRoot, tree->roots, tree->nroots);
-      for (i = 1; i < tree->nroots; ++i)
-        tree->roots[i] = tree->roots[i-1];
-      /* roots[0] will be a copy of the latest version */
+      /* copy the latest version from roots[0] */
+      tree->roots[tree->nroots-1] = tree->roots[0];
       tree->roots[0].version = tree->version;
-
-      // XXX worry about incoming pointers
     }
 }
 
@@ -192,8 +190,6 @@ static GTreeNode*
 g_tree_node_next_version (GTree     *tree,
                           GTreeNode *node)
 {
-  int i;
-
   g_assert(node->version(NOW) <= tree->version);
 
   if (node->version(NOW) == tree->version)
@@ -216,11 +212,10 @@ g_tree_node_next_version (GTree     *tree,
     }
   else
     {
-      /* prepend a version to the node's table */
+      /* add a new version to the node's table */
       node->nv++;
-      for (i = 1; i < node->nv; ++i)
-        node->v[i] = node->v[i-1];
-      /* v[0] will be a copy of the latest version */
+      /* copy the latest version from v[0] */
+      node->v[node->nv-1] = node->v[0];
       node->v[0].version = tree->version;
       return node;