[gtk/wip/baedert/css-values: 75/84] numbervalue: Add early-out to multiply()



commit a9495ee2340a2c5f0b24188dae5644f3b0504d89
Author: Timm Bäder <mail baedert org>
Date:   Tue Jan 14 15:39:48 2020 +0100

    numbervalue: Add early-out to multiply()
    
    If the factor is 1, we already know what the result is going to be.

 gtk/gtkcsscalcvalue.c          | 4 ++--
 gtk/gtkcssdimensionvalue.c     | 4 ++--
 gtk/gtkcssnumbervalue.c        | 7 +++++--
 gtk/gtkcssnumbervalueprivate.h | 4 ++--
 4 files changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkcsscalcvalue.c b/gtk/gtkcsscalcvalue.c
index 162f948b55..55fb47a43e 100644
--- a/gtk/gtkcsscalcvalue.c
+++ b/gtk/gtkcsscalcvalue.c
@@ -211,8 +211,8 @@ gtk_css_value_calc_has_percent (const GtkCssValue *value)
 }
 
 static GtkCssValue *
-gtk_css_value_calc_multiply (const GtkCssValue *value,
-                             double             factor)
+gtk_css_value_calc_multiply (GtkCssValue *value,
+                             double       factor)
 {
   GtkCssValue *result;
   gsize i;
diff --git a/gtk/gtkcssdimensionvalue.c b/gtk/gtkcssdimensionvalue.c
index 0ba4ca9550..afd5ce2798 100644
--- a/gtk/gtkcssdimensionvalue.c
+++ b/gtk/gtkcssdimensionvalue.c
@@ -194,8 +194,8 @@ gtk_css_value_dimension_has_percent (const GtkCssValue *value)
 }
 
 static GtkCssValue *
-gtk_css_value_dimension_multiply (const GtkCssValue *value,
-                                  double             factor)
+gtk_css_value_dimension_multiply (GtkCssValue *value,
+                                  double       factor)
 {
   return gtk_css_dimension_value_new (value->value * factor, value->unit);
 }
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c
index 508ba35c99..625559580e 100644
--- a/gtk/gtkcssnumbervalue.c
+++ b/gtk/gtkcssnumbervalue.c
@@ -44,11 +44,14 @@ gtk_css_number_value_has_percent (const GtkCssValue *value)
 }
 
 GtkCssValue *
-gtk_css_number_value_multiply (const GtkCssValue *value,
-                               double             factor)
+gtk_css_number_value_multiply (GtkCssValue *value,
+                               double       factor)
 {
   GtkCssNumberValueClass *number_value_class = (GtkCssNumberValueClass *) value->class;
 
+  if (factor == 1)
+    return _gtk_css_value_ref (value);
+
   return number_value_class->multiply (value, factor);
 }
 
diff --git a/gtk/gtkcssnumbervalueprivate.h b/gtk/gtkcssnumbervalueprivate.h
index e18b69afcb..040ba902da 100644
--- a/gtk/gtkcssnumbervalueprivate.h
+++ b/gtk/gtkcssnumbervalueprivate.h
@@ -44,7 +44,7 @@ struct _GtkCssNumberValueClass {
                                                      double                  one_hundred_percent);
   GtkCssDimension       (* get_dimension)           (const GtkCssValue      *value);
   gboolean              (* has_percent)             (const GtkCssValue      *value);
-  GtkCssValue *         (* multiply)                (const GtkCssValue      *value,
+  GtkCssValue *         (* multiply)                (GtkCssValue            *value,
                                                      double                  factor);
   GtkCssValue *         (* try_add)                 (GtkCssValue            *value1,
                                                      GtkCssValue            *value2);
@@ -63,7 +63,7 @@ GtkCssValue *   _gtk_css_number_value_parse         (GtkCssParser           *par
 
 GtkCssDimension gtk_css_number_value_get_dimension  (const GtkCssValue      *value) G_GNUC_PURE;
 gboolean        gtk_css_number_value_has_percent    (const GtkCssValue      *value) G_GNUC_PURE;
-GtkCssValue *   gtk_css_number_value_multiply       (const GtkCssValue      *value,
+GtkCssValue *   gtk_css_number_value_multiply       (GtkCssValue            *value,
                                                      double                  factor);
 GtkCssValue *   gtk_css_number_value_add            (GtkCssValue            *value1,
                                                      GtkCssValue            *value2);


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