css: Introduce _gtk_css_value_needs_compute

This returns TRUE for all css values that always compute to themselves
and thus does not need computation. This is useful for the initial
values as these are static and we can avoid computing them in a lot of
cases.
This commit is contained in:
Alexander Larsson
2012-12-04 14:37:23 +01:00
parent ab7e332296
commit cdc5053fd9
21 changed files with 235 additions and 0 deletions

View File

@@ -82,6 +82,20 @@ gtk_css_value_array_compute (GtkCssValue *value,
return result;
}
static gboolean
gtk_css_value_array_needs_compute (const GtkCssValue *value)
{
guint i;
for (i = 0; i < value->n_values; i++)
{
if (_gtk_css_value_needs_compute (value->values[i]))
return TRUE;
}
return FALSE;
}
static gboolean
gtk_css_value_array_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -323,6 +337,7 @@ gtk_css_value_array_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
gtk_css_value_array_free,
gtk_css_value_array_compute,
gtk_css_value_array_needs_compute,
gtk_css_value_array_equal,
gtk_css_value_array_transition,
gtk_css_value_array_print

View File

@@ -69,6 +69,14 @@ gtk_css_value_bg_size_compute (GtkCssValue *value,
value->y ? y : NULL);
}
static gboolean
gtk_css_value_bg_size_needs_compute (const GtkCssValue *value)
{
return
_gtk_css_value_needs_compute (value->x) ||
_gtk_css_value_needs_compute (value->y);
}
static gboolean
gtk_css_value_bg_size_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -150,6 +158,7 @@ gtk_css_value_bg_size_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_BG_SIZE = {
gtk_css_value_bg_size_free,
gtk_css_value_bg_size_compute,
gtk_css_value_bg_size_needs_compute,
gtk_css_value_bg_size_equal,
gtk_css_value_bg_size_transition,
gtk_css_value_bg_size_print

View File

@@ -76,6 +76,20 @@ gtk_css_value_border_compute (GtkCssValue *value,
return computed;
}
static gboolean
gtk_css_value_border_needs_compute (const GtkCssValue *value)
{
guint i;
for (i = 0; i < 4; i++)
{
if (_gtk_css_value_needs_compute (value->values[i]))
return TRUE;
}
return FALSE;
}
static gboolean
gtk_css_value_border_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -136,6 +150,7 @@ gtk_css_value_border_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_BORDER = {
gtk_css_value_border_free,
gtk_css_value_border_compute,
gtk_css_value_border_needs_compute,
gtk_css_value_border_equal,
gtk_css_value_border_transition,
gtk_css_value_border_print

View File

@@ -334,6 +334,12 @@ gtk_css_value_color_compute (GtkCssValue *value,
return resolved;
}
static gboolean
gtk_css_value_color_needs_compute (const GtkCssValue *value)
{
return TRUE;
}
static gboolean
gtk_css_value_color_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -449,6 +455,7 @@ gtk_css_value_color_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_COLOR = {
gtk_css_value_color_free,
gtk_css_value_color_compute,
gtk_css_value_color_needs_compute,
gtk_css_value_color_equal,
gtk_css_value_color_transition,
gtk_css_value_color_print

View File

@@ -60,6 +60,14 @@ gtk_css_value_corner_compute (GtkCssValue *corner,
return _gtk_css_corner_value_new (x, y);
}
static gboolean
gtk_css_value_corner_needs_compute (const GtkCssValue *corner)
{
return
_gtk_css_value_needs_compute (corner->x) ||
_gtk_css_value_needs_compute (corner->y);
}
static gboolean
gtk_css_value_corner_equal (const GtkCssValue *corner1,
const GtkCssValue *corner2)
@@ -104,6 +112,7 @@ gtk_css_value_corner_print (const GtkCssValue *corner,
static const GtkCssValueClass GTK_CSS_VALUE_CORNER = {
gtk_css_value_corner_free,
gtk_css_value_corner_compute,
gtk_css_value_corner_needs_compute,
gtk_css_value_corner_equal,
gtk_css_value_corner_transition,
gtk_css_value_corner_print

View File

@@ -60,6 +60,12 @@ gtk_css_value_ease_compute (GtkCssValue *value,
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_ease_needs_compute (const GtkCssValue *value)
{
return FALSE;
}
static gboolean
gtk_css_value_ease_equal (const GtkCssValue *ease1,
const GtkCssValue *ease2)
@@ -138,6 +144,7 @@ gtk_css_value_ease_print (const GtkCssValue *ease,
static const GtkCssValueClass GTK_CSS_VALUE_EASE = {
gtk_css_value_ease_free,
gtk_css_value_ease_compute,
gtk_css_value_ease_needs_compute,
gtk_css_value_ease_equal,
gtk_css_value_ease_transition,
gtk_css_value_ease_print

View File

@@ -45,6 +45,12 @@ gtk_css_value_engine_compute (GtkCssValue *value,
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_engine_needs_compute (const GtkCssValue *value)
{
return FALSE;
}
static gboolean
gtk_css_value_engine_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -80,6 +86,7 @@ gtk_css_value_engine_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_ENGINE = {
gtk_css_value_engine_free,
gtk_css_value_engine_compute,
gtk_css_value_engine_needs_compute,
gtk_css_value_engine_equal,
gtk_css_value_engine_transition,
gtk_css_value_engine_print

View File

@@ -48,6 +48,12 @@ gtk_css_value_enum_compute (GtkCssValue *value,
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_enum_needs_compute (const GtkCssValue *value)
{
return FALSE;
}
static gboolean
gtk_css_value_enum_equal (const GtkCssValue *enum1,
const GtkCssValue *enum2)
@@ -76,6 +82,7 @@ gtk_css_value_enum_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_BORDER_STYLE = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@@ -219,9 +226,17 @@ gtk_css_value_font_size_compute (GtkCssValue *value,
return _gtk_css_number_value_new (font_size, GTK_CSS_PX);
}
static gboolean
gtk_css_value_font_size_needs_compute (const GtkCssValue *value)
{
return TRUE;
}
static const GtkCssValueClass GTK_CSS_VALUE_FONT_SIZE = {
gtk_css_value_enum_free,
gtk_css_value_font_size_compute,
gtk_css_value_font_size_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@@ -276,6 +291,7 @@ _gtk_css_font_size_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_STYLE = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@@ -324,6 +340,7 @@ _gtk_css_font_style_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@@ -371,6 +388,7 @@ _gtk_css_font_variant_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@@ -439,6 +457,7 @@ _gtk_css_font_weight_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_AREA = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@@ -493,6 +512,7 @@ _gtk_css_area_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_DIRECTION = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@@ -548,6 +568,7 @@ _gtk_css_direction_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_PLAY_STATE = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@@ -601,6 +622,7 @@ _gtk_css_play_state_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FILL_MODE = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_needs_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print

View File

@@ -59,6 +59,12 @@ gtk_css_value_image_compute (GtkCssValue *value,
return _gtk_css_image_value_new (computed);
}
static gboolean
gtk_css_value_image_needs_compute (const GtkCssValue *value)
{
return _gtk_css_image_value_get_image (value) != NULL;
}
static gboolean
gtk_css_value_image_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -95,6 +101,7 @@ gtk_css_value_image_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
gtk_css_value_image_free,
gtk_css_value_image_compute,
gtk_css_value_image_needs_compute,
gtk_css_value_image_equal,
gtk_css_value_image_transition,
gtk_css_value_image_print

View File

@@ -57,6 +57,12 @@ gtk_css_value_inherit_compute (GtkCssValue *value,
}
}
static gboolean
gtk_css_value_inherit_needs_compute (const GtkCssValue *value)
{
return TRUE;
}
static gboolean
gtk_css_value_inherit_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -83,6 +89,7 @@ gtk_css_value_inherit_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
gtk_css_value_inherit_free,
gtk_css_value_inherit_compute,
gtk_css_value_inherit_needs_compute,
gtk_css_value_inherit_equal,
gtk_css_value_inherit_transition,
gtk_css_value_inherit_print

View File

@@ -86,6 +86,12 @@ gtk_css_value_initial_compute (GtkCssValue *value,
dependencies);
}
static gboolean
gtk_css_value_initial_needs_compute (const GtkCssValue *value)
{
return TRUE;
}
static gboolean
gtk_css_value_initial_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -112,6 +118,7 @@ gtk_css_value_initial_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
gtk_css_value_initial_free,
gtk_css_value_initial_compute,
gtk_css_value_initial_needs_compute,
gtk_css_value_initial_equal,
gtk_css_value_initial_transition,
gtk_css_value_initial_print

View File

@@ -123,6 +123,38 @@ gtk_css_value_number_compute (GtkCssValue *number,
}
}
static gboolean
gtk_css_value_number_needs_compute (const GtkCssValue *number)
{
switch (number->unit)
{
default:
g_assert_not_reached();
/* fall through */
case GTK_CSS_PERCENT:
/* percentages for font sizes are computed, other percentages aren't */
return TRUE;
case GTK_CSS_NUMBER:
case GTK_CSS_PX:
case GTK_CSS_DEG:
case GTK_CSS_S:
return FALSE;
case GTK_CSS_PT:
case GTK_CSS_PC:
case GTK_CSS_IN:
case GTK_CSS_CM:
case GTK_CSS_MM:
case GTK_CSS_EM:
case GTK_CSS_EX:
case GTK_CSS_RAD:
case GTK_CSS_GRAD:
case GTK_CSS_TURN:
case GTK_CSS_MS:
return TRUE;
}
}
static gboolean
gtk_css_value_number_equal (const GtkCssValue *number1,
const GtkCssValue *number2)
@@ -180,6 +212,7 @@ gtk_css_value_number_print (const GtkCssValue *number,
static const GtkCssValueClass GTK_CSS_VALUE_NUMBER = {
gtk_css_value_number_free,
gtk_css_value_number_compute,
gtk_css_value_number_needs_compute,
gtk_css_value_number_equal,
gtk_css_value_number_transition,
gtk_css_value_number_print

View File

@@ -60,6 +60,14 @@ gtk_css_value_position_compute (GtkCssValue *position,
return _gtk_css_position_value_new (x, y);
}
static gboolean
gtk_css_value_position_needs_compute (const GtkCssValue *position)
{
return
_gtk_css_value_needs_compute (position->x) ||
_gtk_css_value_needs_compute (position->y);
}
static gboolean
gtk_css_value_position_equal (const GtkCssValue *position1,
const GtkCssValue *position2)
@@ -155,6 +163,7 @@ done:
static const GtkCssValueClass GTK_CSS_VALUE_POSITION = {
gtk_css_value_position_free,
gtk_css_value_position_compute,
gtk_css_value_position_needs_compute,
gtk_css_value_position_equal,
gtk_css_value_position_transition,
gtk_css_value_position_print

View File

@@ -44,6 +44,12 @@ gtk_css_value_repeat_compute (GtkCssValue *value,
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_repeat_needs_compute (const GtkCssValue *value)
{
return FALSE;
}
static gboolean
gtk_css_value_repeat_equal (const GtkCssValue *repeat1,
const GtkCssValue *repeat2)
@@ -116,6 +122,7 @@ gtk_css_value_border_repeat_print (const GtkCssValue *repeat,
static const GtkCssValueClass GTK_CSS_VALUE_BACKGROUND_REPEAT = {
gtk_css_value_repeat_free,
gtk_css_value_repeat_compute,
gtk_css_value_repeat_needs_compute,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
gtk_css_value_background_repeat_print
@@ -124,6 +131,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_BACKGROUND_REPEAT = {
static const GtkCssValueClass GTK_CSS_VALUE_BORDER_REPEAT = {
gtk_css_value_repeat_free,
gtk_css_value_repeat_compute,
gtk_css_value_repeat_needs_compute,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
gtk_css_value_border_repeat_print

View File

@@ -44,6 +44,12 @@ gtk_css_value_rgba_compute (GtkCssValue *value,
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_rgba_needs_compute (const GtkCssValue *value)
{
return FALSE;
}
static gboolean
gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
const GtkCssValue *rgba2)
@@ -80,6 +86,7 @@ gtk_css_value_rgba_print (const GtkCssValue *rgba,
static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
gtk_css_value_rgba_free,
gtk_css_value_rgba_compute,
gtk_css_value_rgba_needs_compute,
gtk_css_value_rgba_equal,
gtk_css_value_rgba_transition,
gtk_css_value_rgba_print

View File

@@ -72,6 +72,20 @@ gtk_css_value_shadows_compute (GtkCssValue *value,
return result;
}
static gboolean
gtk_css_value_shadows_needs_compute (const GtkCssValue *value)
{
guint i;
for (i = 0; i < value->len; i++)
{
if (_gtk_css_value_needs_compute (value->values[i]))
return TRUE;
}
return FALSE;
}
static gboolean
gtk_css_value_shadows_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -181,6 +195,7 @@ gtk_css_value_shadows_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_SHADOWS = {
gtk_css_value_shadows_free,
gtk_css_value_shadows_compute,
gtk_css_value_shadows_needs_compute,
gtk_css_value_shadows_equal,
gtk_css_value_shadows_transition,
gtk_css_value_shadows_print

View File

@@ -94,6 +94,18 @@ gtk_css_value_shadow_compute (GtkCssValue *shadow,
return gtk_css_shadow_value_new (hoffset, voffset, radius, spread, shadow->inset, color);
}
static gboolean
gtk_css_value_shadow_needs_compute (const GtkCssValue *shadow)
{
return
_gtk_css_value_needs_compute (shadow->hoffset) ||
_gtk_css_value_needs_compute (shadow->voffset) ||
_gtk_css_value_needs_compute (shadow->radius) ||
_gtk_css_value_needs_compute (shadow->spread) ||
_gtk_css_value_needs_compute (shadow->color);
}
static gboolean
gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
const GtkCssValue *shadow2)
@@ -154,6 +166,7 @@ gtk_css_value_shadow_print (const GtkCssValue *shadow,
static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
gtk_css_value_shadow_free,
gtk_css_value_shadow_compute,
gtk_css_value_shadow_needs_compute,
gtk_css_value_shadow_equal,
gtk_css_value_shadow_transition,
gtk_css_value_shadow_print

View File

@@ -44,6 +44,12 @@ gtk_css_value_string_compute (GtkCssValue *value,
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_string_needs_compute (const GtkCssValue *value)
{
return FALSE;
}
static gboolean
gtk_css_value_string_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -150,6 +156,7 @@ gtk_css_value_ident_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
gtk_css_value_string_free,
gtk_css_value_string_compute,
gtk_css_value_string_needs_compute,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
gtk_css_value_string_print
@@ -158,6 +165,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
gtk_css_value_string_free,
gtk_css_value_string_compute,
gtk_css_value_string_needs_compute,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
gtk_css_value_ident_print

View File

@@ -47,6 +47,12 @@ gtk_css_value_typed_compute (GtkCssValue *value,
return _gtk_css_style_compute_value (provider, values, parent_values, custom->pspec->value_type, value, dependencies);
}
static gboolean
gtk_css_value_typed_needs_compute (const GtkCssValue *value)
{
return TRUE;
}
static gboolean
gtk_css_value_typed_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@@ -73,6 +79,7 @@ gtk_css_value_typed_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_TYPED = {
gtk_css_value_typed_free,
gtk_css_value_typed_compute,
gtk_css_value_typed_needs_compute,
gtk_css_value_typed_equal,
gtk_css_value_typed_transition,
gtk_css_value_typed_print

View File

@@ -106,6 +106,27 @@ _gtk_css_value_compute (GtkCssValue *value,
return value->class->compute (value, property_id, provider, values, parent_values, dependencies);
}
/**
* _gtk_css_value_needs_compute:
* @value: the value to check or %null
*
* Checks whether a particular css value *really* needs computation.
* A lot of css values are "absolute" (like say "10 px") and never need
* any computation done. Such a value would always just return itself
* as the computed value. This can be used in some cases to avoid
* repeated computations.
*
* Returns: %false if computing this value always returns itself, %false otherwise
**/
gboolean
_gtk_css_value_needs_compute (GtkCssValue *value)
{
if (value == NULL)
return FALSE;
return value->class->needs_compute (value);
}
gboolean
_gtk_css_value_equal (const GtkCssValue *value1,
const GtkCssValue *value2)

View File

@@ -46,6 +46,7 @@ struct _GtkCssValueClass {
GtkCssComputedValues *values,
GtkCssComputedValues *parent_values,
GtkCssDependencies *dependencies);
gboolean (* needs_compute) (const GtkCssValue *value);
gboolean (* equal) (const GtkCssValue *value1,
const GtkCssValue *value2);
GtkCssValue * (* transition) (GtkCssValue *start,
@@ -71,6 +72,7 @@ GtkCssValue *_gtk_css_value_compute (GtkCssValue
GtkCssComputedValues *values,
GtkCssComputedValues *parent_values,
GtkCssDependencies *dependencies);
gboolean _gtk_css_value_needs_compute (GtkCssValue *value);
gboolean _gtk_css_value_equal (const GtkCssValue *value1,
const GtkCssValue *value2);
gboolean _gtk_css_value_equal0 (const GtkCssValue *value1,