From ed3b73871f3dfa34028a795e97ce721f0b820b3e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 3 May 2024 13:07:31 -0400 Subject: [PATCH] css parser: Small optimization Avoid creating a GFile until it is needed. --- gtk/css/gtkcssparser.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gtk/css/gtkcssparser.c b/gtk/css/gtkcssparser.c index ac8c75209f..75744dec4e 100644 --- a/gtk/css/gtkcssparser.c +++ b/gtk/css/gtkcssparser.c @@ -85,10 +85,7 @@ gtk_css_parser_new (GtkCssTokenizer *tokenizer, self->ref_count = 1; self->tokenizer = gtk_css_tokenizer_ref (tokenizer); if (file) - { - self->file = g_object_ref (file); - self->directory = g_file_get_parent (file); - } + self->file = g_object_ref (file); self->error_func = error_func; self->user_data = user_data; @@ -207,7 +204,12 @@ gtk_css_parser_resolve_url (GtkCssParser *self, } if (self->directory == NULL) - return NULL; + { + if (self->file) + self->directory = g_file_get_parent (self->file); + if (self->directory == NULL) + return NULL; + } return g_file_resolve_relative_path (self->directory, url); }