css: Have a separate GtkCssInitialValue per property

This allows us to avoid a lookup in a very common path, and later
cache some more things.
This commit is contained in:
Alexander Larsson
2012-12-03 16:47:18 +01:00
parent 28283e645f
commit ab7e332296
8 changed files with 23 additions and 14 deletions

View File

@@ -137,7 +137,7 @@ _gtk_css_computed_values_compute_value (GtkCssComputedValues *values,
if (_gtk_css_style_property_is_inherit (prop))
specified = _gtk_css_inherit_value_new ();
else
specified = _gtk_css_initial_value_new ();
specified = _gtk_css_initial_value_new (prop);
}
else
_gtk_css_value_ref (specified);

View File

@@ -48,7 +48,7 @@ gtk_css_value_inherit_compute (GtkCssValue *value,
}
else
{
return _gtk_css_value_compute (_gtk_css_initial_value_get (),
return _gtk_css_value_compute (_gtk_css_initial_value_get (_gtk_css_style_property_lookup_by_id (property_id)),
property_id,
provider,
values,

View File

@@ -27,6 +27,7 @@
struct _GtkCssValue {
GTK_CSS_VALUE_BASE
GtkCssStyleProperty *property;
};
static void
@@ -77,7 +78,7 @@ gtk_css_value_initial_compute (GtkCssValue *value,
break;
}
return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (value->property),
property_id,
provider,
values,
@@ -119,13 +120,19 @@ static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
static GtkCssValue initial = { &GTK_CSS_VALUE_INITIAL, 1 };
GtkCssValue *
_gtk_css_initial_value_new (void)
_gtk_css_initial_value_new (GtkCssStyleProperty *property)
{
return _gtk_css_value_ref (&initial);
return _gtk_css_value_ref (_gtk_css_initial_value_get (property));
}
GtkCssValue *
_gtk_css_initial_value_get (void)
_gtk_css_initial_value_get (GtkCssStyleProperty *property)
{
return &initial;
if (property->css_initial_value == NULL)
{
property->css_initial_value = g_new0 (GtkCssValue, 1);
*property->css_initial_value = initial;
property->css_initial_value->property = property;
}
return property->css_initial_value;
}

View File

@@ -21,11 +21,11 @@
#define __GTK_CSS_INITIAL_VALUE_PRIVATE_H__
#include "gtkcssvalueprivate.h"
#include "gtkcssstylepropertyprivate.h"
G_BEGIN_DECLS
GtkCssValue * _gtk_css_initial_value_new (void);
GtkCssValue * _gtk_css_initial_value_get (void);
GtkCssValue * _gtk_css_initial_value_new (GtkCssStyleProperty *property);
GtkCssValue * _gtk_css_initial_value_get (GtkCssStyleProperty *property);
G_END_DECLS

View File

@@ -102,7 +102,7 @@ gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
*/
for (i = 0; i < shorthand->subproperties->len; i++)
{
data[i] = _gtk_css_initial_value_new ();
data[i] = _gtk_css_initial_value_new (shorthand->subproperties->pdata[i]);
}
}
else if (_gtk_css_parser_try (parser, "inherit", TRUE))
@@ -135,7 +135,7 @@ gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
for (i = 0; i < shorthand->subproperties->len; i++)
{
if (data[i] == NULL)
data[i] = _gtk_css_initial_value_new ();
data[i] = _gtk_css_initial_value_new (shorthand->subproperties->pdata[i]);
}
result = _gtk_css_array_value_new_from_array (data, shorthand->subproperties->len);

View File

@@ -230,7 +230,7 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
/* the initial value can be explicitly specified with the
* initial keyword which all properties accept.
*/
return _gtk_css_initial_value_new ();
return _gtk_css_initial_value_new (style_property);
}
else if (_gtk_css_parser_try (parser, "inherit", TRUE))
{

View File

@@ -162,7 +162,7 @@ assign_border (GtkCssStyleProperty *property,
const GtkBorder *border = g_value_get_boxed (value);
if (border == NULL)
return _gtk_css_initial_value_new ();
return _gtk_css_initial_value_new (property);
else
return _gtk_css_border_value_new (_gtk_css_number_value_new (border->top, GTK_CSS_PX),
_gtk_css_number_value_new (border->right, GTK_CSS_PX),

View File

@@ -51,6 +51,8 @@ struct _GtkCssStyleProperty
guint animated :1;
guint affects_size :1;
GtkCssValue *css_initial_value; /* Used to quickly find the GCssInitialValue for a property */
GtkCssStylePropertyParseFunc parse_value;
GtkCssStylePropertyQueryFunc query_value;
GtkCssStylePropertyAssignFunc assign_value;