[gtk+] renderbackground: Avoid excess css value lookups



commit 31974e02ca74a644e75059faed370b031f40f5c6
Author: Timm Bäder <mail baedert org>
Date:   Tue Jan 9 06:12:46 2018 +0100

    renderbackground: Avoid excess css value lookups
    
    We iterate over all background layers twice, so only lookup blend mode
    vlaues once.

 gtk/gtkrenderbackground.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkrenderbackground.c b/gtk/gtkrenderbackground.c
index 57a0741..7957f97 100644
--- a/gtk/gtkrenderbackground.c
+++ b/gtk/gtkrenderbackground.c
@@ -623,9 +623,9 @@ gtk_css_style_snapshot_background (GtkCssStyle      *style,
   GtkCssValue *background_image;
   GtkCssValue *box_shadow;
   GtkCssValue *blend_modes;
-  GskBlendMode blend_mode;
   const GdkRGBA *bg_color;
   gint number_of_layers;
+  GskBlendMode *blend_mode_values;
 
   background_image = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
   bg_color = _gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BACKGROUND_COLOR));
@@ -646,13 +646,15 @@ gtk_css_style_snapshot_background (GtkCssStyle      *style,
 
   blend_modes = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_BLEND_MODE);
   number_of_layers = _gtk_css_array_value_get_n_values (background_image);
+  blend_mode_values = g_alloca (sizeof (GskBlendMode) * number_of_layers);
 
   for (idx = number_of_layers - 1; idx >= 0; idx--)
     {
-      blend_mode = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, idx));
+      blend_mode_values[idx] = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, 
idx));
 
-      if (blend_mode != GSK_BLEND_MODE_DEFAULT)
-        gtk_snapshot_push_blend (snapshot, blend_mode, "Background<%u>Blend<%u>", idx, blend_mode);
+      if (blend_mode_values[idx] != GSK_BLEND_MODE_DEFAULT)
+        gtk_snapshot_push_blend (snapshot, blend_mode_values[idx], "Background<%u>Blend<%u>",
+                                 idx, blend_mode_values[idx]);
     }
 
   if (!gdk_rgba_is_clear (bg_color))
@@ -660,9 +662,7 @@ gtk_css_style_snapshot_background (GtkCssStyle      *style,
 
   for (idx = number_of_layers - 1; idx >= 0; idx--)
     {
-      blend_mode = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, idx));
-
-      if (blend_mode == GSK_BLEND_MODE_DEFAULT)
+      if (blend_mode_values[idx] == GSK_BLEND_MODE_DEFAULT)
         {
           gtk_theming_background_snapshot_layer (&bg, idx, snapshot);
         }


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