dimensionvalue: Add gtk_css_{dimension,corner}_value_is_zero()

We can usually omit computations when the dimension value ends up being
zero anyway.
This commit is contained in:
Timm Bäder 2020-01-25 19:40:13 +01:00
parent 30b37dd7c5
commit 352c9ba42a
4 changed files with 24 additions and 1 deletions

View File

@ -18,8 +18,8 @@
#include "config.h"
#include "gtkcsscornervalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkcssdimensionvalueprivate.h"
struct _GtkCssValue {
GTK_CSS_VALUE_BASE
@ -184,3 +184,12 @@ _gtk_css_corner_value_get_y (const GtkCssValue *corner,
return _gtk_css_number_value_get (corner->y, one_hundred_percent);
}
gboolean
gtk_css_corner_value_is_zero (const GtkCssValue *corner)
{
if (corner->class != &GTK_CSS_VALUE_CORNER)
return gtk_css_dimension_value_is_zero (corner);
return gtk_css_dimension_value_is_zero (corner->x) &&
gtk_css_dimension_value_is_zero (corner->y);
}

View File

@ -33,6 +33,7 @@ double _gtk_css_corner_value_get_x (const GtkCssValue *cor
double one_hundred_percent) G_GNUC_PURE;
double _gtk_css_corner_value_get_y (const GtkCssValue *corner,
double one_hundred_percent) G_GNUC_PURE;
gboolean gtk_css_corner_value_is_zero (const GtkCssValue *corner) G_GNUC_PURE;
G_END_DECLS

View File

@ -497,3 +497,14 @@ gtk_css_dimension_value_parse (GtkCssParser *parser,
return result;
}
gboolean
gtk_css_dimension_value_is_zero (const GtkCssValue *value)
{
if (!value)
return TRUE;
if (value->class != &GTK_CSS_VALUE_DIMENSION.value_class)
return FALSE;
return value->value == 0;
}

View File

@ -30,6 +30,8 @@ GtkCssValue * gtk_css_dimension_value_new (double val
GtkCssValue * gtk_css_dimension_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags);
gboolean gtk_css_dimension_value_is_zero (const GtkCssValue *value) G_GNUC_PURE;
G_END_DECLS
#endif /* __GTK_CSS_DIMENSION_VALUE_PRIVATE_H__ */