[gtk+/wip/baedert/gtkimageview: 255/255] stylecontext: Use a GPtrArray for saved nodes



commit f8c3a34543d7e780c90cab75a13c9d5539ff2fb5
Author: Timm Bäder <mail baedert org>
Date:   Sat Apr 30 18:46:51 2016 +0200

    stylecontext: Use a GPtrArray for saved nodes

 gtk/gtkstylecontext.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index f5da8ca..246f6db 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -140,7 +140,7 @@ struct _GtkStyleContextPrivate
   GtkStyleCascade *cascade;
   GtkStyleContext *parent;
   GtkCssNode *cssnode;
-  GSList *saved_nodes;
+  GPtrArray *saved_nodes;
   GArray *property_cache;
 
   GdkFrameClock *frame_clock;
@@ -271,14 +271,17 @@ static void
 gtk_style_context_pop_style_node (GtkStyleContext *context)
 {
   GtkStyleContextPrivate *priv = context->priv;
+  guint index;
 
-  g_return_if_fail (priv->saved_nodes != NULL);
+  g_return_if_fail (priv->saved_nodes->len > 0);
 
   if (GTK_IS_CSS_TRANSIENT_NODE (priv->cssnode))
     gtk_css_node_set_parent (priv->cssnode, NULL);
   g_object_unref (priv->cssnode);
-  priv->cssnode = priv->saved_nodes->data;
-  priv->saved_nodes = g_slist_remove (priv->saved_nodes, priv->cssnode);
+
+  index = priv->saved_nodes->len - 1;
+  priv->cssnode = g_ptr_array_index (priv->saved_nodes, index);
+  g_ptr_array_remove_index (priv->saved_nodes, index);
 }
 
 static void
@@ -334,6 +337,7 @@ gtk_style_context_init (GtkStyleContext *context)
     g_error ("Can't create a GtkStyleContext without a display connection");
 
   priv->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
+  priv->saved_nodes = g_ptr_array_new ();
 
   gtk_style_context_set_cascade (context,
                                  _gtk_settings_get_style_cascade (gtk_settings_get_for_screen 
(priv->screen), 1));
@@ -358,7 +362,7 @@ gtk_style_context_finalize (GObject *object)
   GtkStyleContext *context = GTK_STYLE_CONTEXT (object);
   GtkStyleContextPrivate *priv = context->priv;
 
-  while (priv->saved_nodes)
+  while (priv->saved_nodes->len > 0)
     gtk_style_context_pop_style_node (context);
 
   if (GTK_IS_CSS_PATH_NODE (priv->cssnode))
@@ -371,6 +375,7 @@ gtk_style_context_finalize (GObject *object)
 
   gtk_style_context_clear_property_cache (context);
   g_array_free (priv->property_cache, TRUE);
+  g_ptr_array_free (priv->saved_nodes, TRUE);
 
   G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
 }
@@ -444,7 +449,7 @@ gtk_style_context_impl_get_property (GObject    *object,
 static gboolean
 gtk_style_context_is_saved (GtkStyleContext *context)
 {
-  return context->priv->saved_nodes != NULL;
+  return context->priv->saved_nodes->len > 0;
 }
 
 static GtkCssNode *
@@ -452,8 +457,8 @@ gtk_style_context_get_root (GtkStyleContext *context)
 {
   GtkStyleContextPrivate *priv = context->priv;
 
-  if (priv->saved_nodes != NULL)
-    return g_slist_last (priv->saved_nodes)->data;
+  if (priv->saved_nodes->len > 0)
+    return g_ptr_array_index (priv->saved_nodes, 0);
   else
     return priv->cssnode;
 }
@@ -1226,7 +1231,7 @@ gtk_style_context_save_to_node (GtkStyleContext *context,
 
   priv = context->priv;
 
-  priv->saved_nodes = g_slist_prepend (priv->saved_nodes, priv->cssnode);
+  g_ptr_array_add (priv->saved_nodes, priv->cssnode);
   priv->cssnode = g_object_ref (node);
 }
 
@@ -1291,7 +1296,7 @@ gtk_style_context_restore (GtkStyleContext *context)
 {
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
-  if (context->priv->saved_nodes == NULL)
+  if (context->priv->saved_nodes->len == 0)
     {
       g_warning ("Unpaired gtk_style_context_restore() call");
       return;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]