[gtk/wip/baedert/css-values: 5/6] numbervalue: Add early-out to multiply()
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/css-values: 5/6] numbervalue: Add early-out to multiply()
- Date: Tue, 14 Jan 2020 14:55:33 +0000 (UTC)
commit 77283945c0f317906b4d0dc27b226a1ef6968cdb
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/gtkcssnumbervalue.c | 7 +++++--
gtk/gtkcssnumbervalueprivate.h | 4 ++--
2 files changed, 7 insertions(+), 4 deletions(-)
---
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]