From 26f2d548405adae3881349b9aa7e07fcad3ab023 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 12 Sep 2024 14:42:28 +0100 Subject: [PATCH] gresource: Avoid a gettext lookup on a hot error path See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4242#note_2215991 Signed-off-by: Philip Withnall Helps: #3465 --- gio/gresource.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gio/gresource.c b/gio/gresource.c index 53bf742d5..d63e4e8a5 100644 --- a/gio/gresource.c +++ b/gio/gresource.c @@ -679,9 +679,11 @@ static void set_error_not_found (GError **error, const char *path) { - g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, - _("The resource at “%s” does not exist"), - path); + /* Avoid looking up the translation if it’s not going to be used. This is a hot path. */ + if (error != NULL) + g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, + _("The resource at “%s” does not exist"), + path); } /* The only error this can return is %G_RESOURCE_ERROR_NOT_FOUND. */