[gtk+/wip/css-optimize2: 5/10] css: Have a separate GtkCssInitialValue per property
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css-optimize2: 5/10] css: Have a separate GtkCssInitialValue per property
- Date: Tue, 4 Dec 2012 16:01:40 +0000 (UTC)
commit ab7e332296c69ef45bf798ed4c8efd27a89c972f
Author: Alexander Larsson <alexl redhat com>
Date: Mon Dec 3 16:47:18 2012 +0100
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.
gtk/gtkcsscomputedvalues.c | 2 +-
gtk/gtkcssinheritvalue.c | 2 +-
gtk/gtkcssinitialvalue.c | 17 ++++++++++++-----
gtk/gtkcssinitialvalueprivate.h | 6 +++---
gtk/gtkcssshorthandproperty.c | 4 ++--
gtk/gtkcssstyleproperty.c | 2 +-
gtk/gtkcssstylepropertyimpl.c | 2 +-
gtk/gtkcssstylepropertyprivate.h | 2 ++
8 files changed, 23 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkcsscomputedvalues.c b/gtk/gtkcsscomputedvalues.c
index dea23bd..eb2210d 100644
--- a/gtk/gtkcsscomputedvalues.c
+++ b/gtk/gtkcsscomputedvalues.c
@@ -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);
diff --git a/gtk/gtkcssinheritvalue.c b/gtk/gtkcssinheritvalue.c
index e2c3f16..4699c84 100644
--- a/gtk/gtkcssinheritvalue.c
+++ b/gtk/gtkcssinheritvalue.c
@@ -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,
diff --git a/gtk/gtkcssinitialvalue.c b/gtk/gtkcssinitialvalue.c
index 427044d..4db1bb4 100644
--- a/gtk/gtkcssinitialvalue.c
+++ b/gtk/gtkcssinitialvalue.c
@@ -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 = { >K_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;
}
diff --git a/gtk/gtkcssinitialvalueprivate.h b/gtk/gtkcssinitialvalueprivate.h
index 185e1be..6fa30ea 100644
--- a/gtk/gtkcssinitialvalueprivate.h
+++ b/gtk/gtkcssinitialvalueprivate.h
@@ -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
diff --git a/gtk/gtkcssshorthandproperty.c b/gtk/gtkcssshorthandproperty.c
index c6ca614..752d877 100644
--- a/gtk/gtkcssshorthandproperty.c
+++ b/gtk/gtkcssshorthandproperty.c
@@ -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);
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index bd7d5a0..5f53f5b 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -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))
{
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 3d8eb21..4ed1779 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -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),
diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h
index 00d8437..8a88bb4 100644
--- a/gtk/gtkcssstylepropertyprivate.h
+++ b/gtk/gtkcssstylepropertyprivate.h
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]