minor optimization.
[platform/upstream/glib.git] / gnode.c
diff --git a/gnode.c b/gnode.c
index c9c135a..5db03c6 100644 (file)
--- a/gnode.c
+++ b/gnode.c
  * Boston, MA 02111-1307, USA.
  */
 
+/*
+ * Modified by the GLib Team and others 1997-1999.  See the AUTHORS
+ * file for a list of people on the GLib Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
 /* 
  * MT safe
  */
@@ -39,7 +46,7 @@ struct _GAllocator /* from gmem.c */
   GNode         *free_nodes; /* implementation specific */
 };
 
-static G_LOCK_DEFINE(current_allocator);
+G_LOCK_DEFINE_STATIC (current_allocator);
 static GAllocator *current_allocator = NULL;
 
 /* HOLDS: current_allocator_lock */
@@ -74,17 +81,17 @@ g_node_validate_allocator (GAllocator *allocator)
 void
 g_node_push_allocator (GAllocator *allocator)
 {
-  g_lock (current_allocator);
+  G_LOCK (current_allocator);
   g_node_validate_allocator ( allocator );
   allocator->last = current_allocator;
   current_allocator = allocator;
-  g_unlock (current_allocator);
+  G_UNLOCK (current_allocator);
 }
 
 void
 g_node_pop_allocator (void)
 {
-  g_lock (current_allocator);
+  G_LOCK (current_allocator);
   if (current_allocator)
     {
       GAllocator *allocator;
@@ -94,7 +101,7 @@ g_node_pop_allocator (void)
       allocator->last = NULL;
       allocator->is_unused = TRUE;
     }
-  g_unlock (current_allocator);
+  G_UNLOCK (current_allocator);
 }
 
 
@@ -104,11 +111,11 @@ g_node_new (gpointer data)
 {
   GNode *node;
 
-  g_lock (current_allocator);
+  G_LOCK (current_allocator);
   if (!current_allocator)
     {
        GAllocator *allocator = g_allocator_new ("GLib default GNode allocator",
-                                               1024);
+                                               128);
        g_node_validate_allocator (allocator);
        allocator->last = NULL;
        current_allocator = allocator;
@@ -120,7 +127,7 @@ g_node_new (gpointer data)
       node = current_allocator->free_nodes;
       current_allocator->free_nodes = node->next;
     }
-  g_unlock (current_allocator);
+  G_UNLOCK (current_allocator);
   
   node->data = data;
   node->next = NULL;
@@ -147,10 +154,10 @@ g_nodes_free (GNode *node)
        break;
     }
   
-  g_lock (current_allocator);
+  G_LOCK (current_allocator);
   parent->next = current_allocator->free_nodes;
   current_allocator->free_nodes = node;
-  g_unlock (current_allocator);
+  G_UNLOCK (current_allocator);
 }
 
 void
@@ -183,6 +190,24 @@ g_node_unlink (GNode *node)
 }
 
 GNode*
+g_node_copy (GNode *node)
+{
+  GNode *new_node = NULL;
+  
+  if (node)
+    {
+      GNode *child;
+      
+      new_node = g_node_new (node->data);
+      
+      for (child = g_node_last_child (node); child; child = child->prev)
+       g_node_prepend (new_node, g_node_copy (child));
+    }
+  
+  return new_node;
+}
+
+GNode*
 g_node_insert (GNode *parent,
               gint   position,
               GNode *node)
@@ -910,6 +935,9 @@ g_node_first_sibling (GNode *node)
 {
   g_return_val_if_fail (node != NULL, NULL);
   
+  if (node->parent)
+    return node->parent->children;
+  
   while (node->prev)
     node = node->prev;