[gtk+] css style: Accumulate changes in place



commit 130fc6ce9bb8e5df381b9e6956fb42ea889bb769
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Sep 28 01:43:03 2015 -0400

    css style: Accumulate changes in place
    
    This avoids allocating a temporary bitmask, and lets us
    avoid some value comparisons altogether.

 gtk/gtkcssstyle.c        |   16 +++++++++-------
 gtk/gtkcssstyleprivate.h |    3 ++-
 gtk/gtkcsswidgetnode.c   |    7 ++-----
 3 files changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c
index c4afe13..d577dc7 100644
--- a/gtk/gtkcssstyle.c
+++ b/gtk/gtkcssstyle.c
@@ -83,25 +83,27 @@ gtk_css_style_get_section (GtkCssStyle *style,
 }
 
 GtkBitmask *
-gtk_css_style_get_difference (GtkCssStyle *style,
+gtk_css_style_add_difference (GtkBitmask  *accumulated,
+                              GtkCssStyle *style,
                               GtkCssStyle *other)
 {
-  GtkBitmask *result;
-  guint i, len;
+  gint len, i;
 
   if (style == other)
-    return _gtk_bitmask_new ();
+    return accumulated;
 
-  result = _gtk_bitmask_new ();
   len = _gtk_css_style_property_get_n_properties ();
   for (i = 0; i < len; i++)
     {
+      if (_gtk_bitmask_get (accumulated, i))
+        continue;
+
       if (!_gtk_css_value_equal (gtk_css_style_get_value (style, i),
                                  gtk_css_style_get_value (other, i)))
-        result = _gtk_bitmask_set (result, i, TRUE);
+        accumulated = _gtk_bitmask_set (accumulated, i, TRUE);
     }
 
-  return result;
+  return accumulated;
 }
 
 gboolean
diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h
index d3226a6..ff02980 100644
--- a/gtk/gtkcssstyleprivate.h
+++ b/gtk/gtkcssstyleprivate.h
@@ -64,7 +64,8 @@ GtkCssValue *           gtk_css_style_get_value                 (GtkCssStyle
                                                                  guint                   id);
 GtkCssSection *         gtk_css_style_get_section               (GtkCssStyle            *style,
                                                                  guint                   id);
-GtkBitmask *            gtk_css_style_get_difference            (GtkCssStyle            *style,
+GtkBitmask *            gtk_css_style_add_difference            (GtkBitmask             *accumulated,
+                                                                 GtkCssStyle            *style,
                                                                  GtkCssStyle            *other);
 gboolean                gtk_css_style_is_static                 (GtkCssStyle            *style);
 
diff --git a/gtk/gtkcsswidgetnode.c b/gtk/gtkcsswidgetnode.c
index cf68fb4..5e93101 100644
--- a/gtk/gtkcsswidgetnode.c
+++ b/gtk/gtkcsswidgetnode.c
@@ -50,7 +50,6 @@ gtk_css_widget_node_style_changed (GtkCssNode   *cssnode,
                                    GtkCssStyle  *new_style)
 {
   GtkCssWidgetNode *node;
-  GtkBitmask *diff;
 
   node = GTK_CSS_WIDGET_NODE (cssnode);
 
@@ -59,9 +58,7 @@ gtk_css_widget_node_style_changed (GtkCssNode   *cssnode,
 
   GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->style_changed (cssnode, old_style, new_style);
 
-  diff = gtk_css_style_get_difference (new_style, old_style);
-  node->accumulated_changes = _gtk_bitmask_union (node->accumulated_changes, diff);
-  _gtk_bitmask_free (diff);
+  node->accumulated_changes = gtk_css_style_add_difference (node->accumulated_changes, new_style, old_style);
 }
 
 static gboolean
@@ -70,7 +67,7 @@ gtk_css_widget_node_queue_callback (GtkWidget     *widget,
                                     gpointer       user_data)
 {
   GtkCssNode *node = user_data;
-  
+
   gtk_css_node_invalidate_frame_clock (node, TRUE);
   _gtk_container_queue_restyle (GTK_CONTAINER (widget));
 


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