diff --git a/src/st/st-theme.c b/src/st/st-theme.c index 9867ee151..9ad99e2b1 100644 --- a/src/st/st-theme.c +++ b/src/st/st-theme.c @@ -244,6 +244,27 @@ insert_stylesheet (StTheme *theme, g_hash_table_insert (theme->files_by_stylesheet, stylesheet, file); } +static CRStyleSheet * +resolve_stylesheet (StTheme *theme, + GFile *file, + GError **error) +{ + CRStyleSheet *sheet; + + sheet = g_hash_table_lookup (theme->stylesheets_by_file, file); + if (sheet) + { + cr_stylesheet_ref (sheet); + return sheet; + } + + sheet = parse_stylesheet (file, error); + if (sheet) + insert_stylesheet (theme, file, sheet); + + return sheet; +} + /** * st_theme_load_stylesheet: * @theme: a #StTheme @@ -261,13 +282,12 @@ st_theme_load_stylesheet (StTheme *theme, { CRStyleSheet *stylesheet; - stylesheet = parse_stylesheet (file, error); + stylesheet = resolve_stylesheet (theme, file, error); if (!stylesheet) return FALSE; stylesheet->app_data = GUINT_TO_POINTER (TRUE); - insert_stylesheet (theme, file, stylesheet); cr_stylesheet_ref (stylesheet); theme->custom_stylesheets = g_slist_prepend (theme->custom_stylesheets, stylesheet); g_signal_emit (theme, signals[STYLESHEETS_CHANGED], 0); @@ -884,6 +904,7 @@ add_matched_properties (StTheme *a_this, if (import_rule->sheet == NULL) { + CRStyleSheet *sheet = NULL; GFile *file = NULL; if (import_rule->url->stryng && import_rule->url->stryng->str) @@ -891,13 +912,12 @@ add_matched_properties (StTheme *a_this, file = _st_theme_resolve_url (a_this, a_nodesheet, import_rule->url->stryng->str); - import_rule->sheet = parse_stylesheet (file, NULL); + sheet = resolve_stylesheet (a_this, file, NULL); } - if (import_rule->sheet) + if (sheet) { - insert_stylesheet (a_this, file, import_rule->sheet); - /* refcount of stylesheets starts off at zero, so we don't need to unref! */ + import_rule->sheet = sheet; } else {