[gtk/wip/baedert/css-values: 8/17] cssdimensionvalue: Mark percentage values as is_computed



commit 3dd361af91d01738264aa753b0c384a619b26838
Author: Timm Bäder <mail baedert org>
Date:   Wed Jan 15 10:00:12 2020 +0100

    cssdimensionvalue: Mark percentage values as is_computed
    
    This spares us from computing percentages everywhere, just because they
    may not-be computed in the font-size case. This case is handled by
    GtkCssFontSizeValue now.
    
    This spares us gtk_css_value_compute() calls for roughly 16000
    GtkCssDimensionValue instances on startup of the widget-factory.

 gtk/gtkcssdimensionvalue.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkcssdimensionvalue.c b/gtk/gtkcssdimensionvalue.c
index a849a2948b..fe18348009 100644
--- a/gtk/gtkcssdimensionvalue.c
+++ b/gtk/gtkcssdimensionvalue.c
@@ -72,12 +72,6 @@ gtk_css_value_dimension_compute (GtkCssValue      *number,
       g_assert_not_reached();
       G_GNUC_FALLTHROUGH;
     case GTK_CSS_PERCENT:
-      /* percentages for font sizes are computed, other percentages aren't */
-      if (property_id == GTK_CSS_PROPERTY_FONT_SIZE)
-        return gtk_css_dimension_value_new (number->value / 100.0 * 
-                                            get_base_font_size_px (property_id, provider, style, 
parent_style),
-                                            GTK_CSS_PX);
-      G_GNUC_FALLTHROUGH;
     case GTK_CSS_NUMBER:
     case GTK_CSS_PX:
     case GTK_CSS_DEG:
@@ -296,8 +290,8 @@ gtk_css_dimension_value_new (double     value,
   };
   static GtkCssValue percent_singletons[] = {
     { &GTK_CSS_VALUE_DIMENSION.value_class, 1, TRUE, GTK_CSS_PERCENT, 0 },
-    { &GTK_CSS_VALUE_DIMENSION.value_class, 1, FALSE, GTK_CSS_PERCENT, 50 },
-    { &GTK_CSS_VALUE_DIMENSION.value_class, 1, FALSE, GTK_CSS_PERCENT, 100 },
+    { &GTK_CSS_VALUE_DIMENSION.value_class, 1, TRUE, GTK_CSS_PERCENT, 50 },
+    { &GTK_CSS_VALUE_DIMENSION.value_class, 1, TRUE, GTK_CSS_PERCENT, 100 },
   };
   static GtkCssValue second_singletons[] = {
     { &GTK_CSS_VALUE_DIMENSION.value_class, 1, TRUE, GTK_CSS_S, 0 },
@@ -379,6 +373,7 @@ gtk_css_dimension_value_new (double     value,
                         unit == GTK_CSS_NUMBER ||
                         unit == GTK_CSS_PX ||
                         unit == GTK_CSS_DEG ||
+                        unit == GTK_CSS_PERCENT ||
                         unit == GTK_CSS_S;
 
   return result;


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