From: Dana Jansens Date: Fri, 30 Oct 2009 13:33:07 +0000 (-0400) Subject: Don't prepend new versions into the versioned-pointer arrays, so that new ones can... X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=ae90a7bd78180e3a3be3cda3defacb0dc6d19b29;p=dana%2Fcg-glib.git Don't prepend new versions into the versioned-pointer arrays, so that new ones can be added in O(1) time. Keep the newest at the front of the array though. --- diff --git a/glib/gtree.c b/glib/gtree.c index 894ac697..c11a6a4e 100644 --- a/glib/gtree.c +++ b/glib/gtree.c @@ -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;