[gtk+/wip/cssvalue] widget: Don't cache widget paths all the time



commit 219ec7e1d0008ee8bf3bffade28cff101b381284
Author: Benjamin Otte <otte redhat com>
Date:   Sat Apr 7 14:15:35 2012 +0200

    widget: Don't cache widget paths all the time
    
    Add an internal API that allows GtkStyleContext to create a widget path
    for the widget and with that bypassing gtk_widget_get_path() and that
      function caching the path.

 gtk/gtkstylecontext.c  |    2 +-
 gtk/gtkwidget.c        |   61 ++++++++++++++++++++++++++---------------------
 gtk/gtkwidgetprivate.h |    1 +
 3 files changed, 36 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 80bf78e..9f81145 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -745,7 +745,7 @@ create_query_path (GtkStyleContext *context)
   guint i, pos;
 
   priv = context->priv;
-  path = gtk_widget_path_copy (priv->widget ? gtk_widget_get_path (priv->widget) : priv->widget_path);
+  path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
   pos = gtk_widget_path_length (path) - 1;
 
   info = priv->info_stack->data;
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 066380b..2e6dd45 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -13897,6 +13897,39 @@ gtk_widget_path_append_for_widget (GtkWidgetPath *path,
   return pos;
 }
 
+GtkWidgetPath *
+_gtk_widget_create_path (GtkWidget *widget)
+{
+  GtkWidget *parent;
+
+  parent = widget->priv->parent;
+
+  if (parent)
+    return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
+  else
+    {
+      /* Widget is either toplevel or unparented, treat both
+       * as toplevels style wise, since there are situations
+       * where style properties might be retrieved on that
+       * situation.
+       */
+      GtkWidget *attach_widget = NULL;
+      GtkWidgetPath *result;
+
+      if (GTK_IS_WINDOW (widget))
+        attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
+
+      if (attach_widget != NULL)
+        result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
+      else
+        result = gtk_widget_path_new ();
+
+      gtk_widget_path_append_for_widget (result, widget);
+
+      return result;
+    }
+}
+
 /**
  * gtk_widget_get_path:
  * @widget: a #GtkWidget
@@ -13913,33 +13946,7 @@ gtk_widget_get_path (GtkWidget *widget)
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
   if (!widget->priv->path)
-    {
-      GtkWidget *parent;
-
-      parent = widget->priv->parent;
-
-      if (parent)
-        widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
-      else
-        {
-          /* Widget is either toplevel or unparented, treat both
-           * as toplevels style wise, since there are situations
-           * where style properties might be retrieved on that
-           * situation.
-           */
-          GtkWidget *attach_widget = NULL;
-
-          if (GTK_IS_WINDOW (widget))
-            attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
-
-          if (attach_widget != NULL)
-            widget->priv->path = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
-          else
-            widget->priv->path = gtk_widget_path_new ();
-    
-          gtk_widget_path_append_for_widget (widget->priv->path, widget);
-        }
-    }
+    widget->priv->path = _gtk_widget_create_path (widget);
 
   return widget->priv->path;
 }
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 5cf44dd..fa5e9b8 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -176,6 +176,7 @@ void              _gtk_widget_set_captured_event_handler (GtkWidget
 gboolean          _gtk_widget_captured_event               (GtkWidget *widget,
                                                             GdkEvent  *event);
 
+GtkWidgetPath *   _gtk_widget_create_path                  (GtkWidget    *widget);
 void              _gtk_widget_invalidate_style_context     (GtkWidget    *widget,
                                                             GtkCssChange  change);
 void              _gtk_widget_style_context_invalidated    (GtkWidget    *widget);



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