Keep similar theme nodes so we don't have to recompute CSS so often

Because we calculate and cache CSS properties once per StThemeNode,
and only a certain set of attributes can affect the CSS properties,
it's advantageous for as many widgets as possible to share a single
StThemeNode. Similarly, if a widget changes state and then changes back
(e.g. gaining and losing the :hover pseudo-class), it should ideally
get its original StThemeNode back again when it returns to the old
state.

Here, I'm using the StThemeContext as the location for a cache.
StThemeNodes are currently never freed: this seems OK for Shell's usage
(a finite number of IDs, classes, pseudo-classes and types).

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=687465
Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
This commit is contained in:
Simon McVittie
2012-11-08 17:50:01 +00:00
parent 2cfed952bb
commit dc2ec0a8f9
5 changed files with 85 additions and 7 deletions

View File

@ -390,6 +390,40 @@ st_theme_node_equal (StThemeNode *node_a, StThemeNode *node_b)
return TRUE;
}
guint
st_theme_node_hash (StThemeNode *node)
{
guint hash = GPOINTER_TO_UINT (node->parent_node);
hash = hash * 33 + GPOINTER_TO_UINT (node->context);
hash = hash * 33 + GPOINTER_TO_UINT (node->theme);
hash = hash * 33 + ((guint) node->element_type);
if (node->element_id != NULL)
hash = hash * 33 + g_str_hash (node->element_id);
if (node->inline_style != NULL)
hash = hash * 33 + g_str_hash (node->inline_style);
if (node->element_classes != NULL)
{
gchar **it;
for (it = node->element_classes; *it != NULL; it++)
hash = hash * 33 + g_str_hash (*it) + 1;
}
if (node->pseudo_classes != NULL)
{
gchar **it;
for (it = node->pseudo_classes; *it != NULL; it++)
hash = hash * 33 + g_str_hash (*it) + 1;
}
return hash;
}
static void
ensure_properties (StThemeNode *node)
{