css: short-circuit gtk_css_dimension_value_try_add

No need to allocate a new css value for something that we already have,
because one of the two values is 0
This commit is contained in:
Timm Bäder 2019-11-07 07:32:03 +01:00
parent cd3cd64769
commit edf56b438e
4 changed files with 16 additions and 10 deletions

View File

@ -228,8 +228,8 @@ gtk_css_value_calc_multiply (const GtkCssValue *value,
}
static GtkCssValue *
gtk_css_value_calc_try_add (const GtkCssValue *value1,
const GtkCssValue *value2)
gtk_css_value_calc_try_add (GtkCssValue *value1,
GtkCssValue *value2)
{
return NULL;
}

View File

@ -235,12 +235,18 @@ gtk_css_value_dimension_multiply (const GtkCssValue *value,
}
static GtkCssValue *
gtk_css_value_dimension_try_add (const GtkCssValue *value1,
const GtkCssValue *value2)
gtk_css_value_dimension_try_add (GtkCssValue *value1,
GtkCssValue *value2)
{
if (value1->unit != value2->unit)
return NULL;
if (value1->value == 0)
return _gtk_css_value_ref (value2);
if (value2->value == 0)
return _gtk_css_value_ref (value1);
return gtk_css_dimension_value_new (value1->value + value2->value, value1->unit);
}

View File

@ -66,8 +66,8 @@ gtk_css_number_value_add (GtkCssValue *value1,
}
GtkCssValue *
gtk_css_number_value_try_add (const GtkCssValue *value1,
const GtkCssValue *value2)
gtk_css_number_value_try_add (GtkCssValue *value1,
GtkCssValue *value2)
{
GtkCssNumberValueClass *number_value_class;

View File

@ -46,8 +46,8 @@ struct _GtkCssNumberValueClass {
gboolean (* has_percent) (const GtkCssValue *value);
GtkCssValue * (* multiply) (const GtkCssValue *value,
double factor);
GtkCssValue * (* try_add) (const GtkCssValue *value1,
const GtkCssValue *value2);
GtkCssValue * (* try_add) (GtkCssValue *value1,
GtkCssValue *value2);
gint (* get_calc_term_order) (const GtkCssValue *value);
};
@ -67,8 +67,8 @@ GtkCssValue * gtk_css_number_value_multiply (const GtkCssValue *val
double factor);
GtkCssValue * gtk_css_number_value_add (GtkCssValue *value1,
GtkCssValue *value2);
GtkCssValue * gtk_css_number_value_try_add (const GtkCssValue *value1,
const GtkCssValue *value2);
GtkCssValue * gtk_css_number_value_try_add (GtkCssValue *value1,
GtkCssValue *value2);
gint gtk_css_number_value_get_calc_term_order (const GtkCssValue *value);
double _gtk_css_number_value_get (const GtkCssValue *number,