[gtk+/wip/cssvalue: 38/142] stylecontext: Don't clear cache when only state changes



commit 72095e6f591b50d1601fffe79f3e5771d06a897d
Author: Benjamin Otte <otte redhat com>
Date:   Sat Mar 24 02:15:41 2012 +0100

    stylecontext: Don't clear cache when only state changes
    
    This takes more memory, but changes to backdrop or active state are
    quite expensive otherwise.

 gtk/gtkstylecontext.c |   51 ++++++++++++++++++++++++++++++------------------
 1 files changed, 32 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 495e31b..c1b9387 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -304,6 +304,9 @@
 /* When these change we do a full restyling. Otherwise we try to figure out
  * if we need to change things. */
 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS)
+/* When these change we don't clear the cache. This takes more memory but makes
+ * things go faster. */
+#define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
 
 typedef struct GtkStyleInfo GtkStyleInfo;
 typedef struct GtkRegion GtkRegion;
@@ -3271,6 +3274,31 @@ store_animation_region (GtkStyleContext *context,
     }
 }
 
+static void
+gtk_style_context_do_invalidate (GtkStyleContext *context,
+                                 gboolean         clear_caches)
+{
+  GtkStyleContextPrivate *priv;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+  priv = context->priv;
+
+  /* Avoid reentrancy */
+  if (priv->invalidating_context)
+    return;
+
+  priv->invalidating_context = TRUE;
+
+  if (clear_caches)
+    g_hash_table_remove_all (priv->style_data);
+  priv->current_data = NULL;
+
+  g_signal_emit (context, signals[CHANGED], 0);
+
+  priv->invalidating_context = FALSE;
+}
+
 void
 _gtk_style_context_validate (GtkStyleContext *context,
                              GtkCssChange     change)
@@ -3315,7 +3343,9 @@ _gtk_style_context_validate (GtkStyleContext *context,
 
   if (priv->relevant_changes & change)
     {
-      gtk_style_context_invalidate (context);
+      gboolean clear_cache = ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE) != 0;
+
+      gtk_style_context_do_invalidate (context, clear_cache);
     }
 
   change = _gtk_css_change_for_child (change);
@@ -3359,26 +3389,9 @@ _gtk_style_context_queue_invalidate (GtkStyleContext *context,
 void
 gtk_style_context_invalidate (GtkStyleContext *context)
 {
-  GtkStyleContextPrivate *priv;
-
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
-  priv = context->priv;
-
-  /* Avoid reentrancy */
-  if (priv->invalidating_context)
-    return;
-
-  priv->invalidating_context = TRUE;
-
-  g_hash_table_remove_all (priv->style_data);
-  priv->current_data = NULL;
-
-  priv->relevant_changes = GTK_CSS_CHANGE_ANY;
-
-  g_signal_emit (context, signals[CHANGED], 0);
-
-  priv->invalidating_context = FALSE;
+  gtk_style_context_do_invalidate (context, TRUE);
 }
 
 /**



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