From 8913f092873f73689ea6bc7ff6e98767e0648f74 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 15 Feb 2024 19:34:16 +0100 Subject: [PATCH] localename-unsafe: Optimize. * lib/localename-unsafe.c (gl_locale_name_posix_unsafe): Call setlocale_null_unlocked instead of setlocale_null. * modules/localename-unsafe (Depends-on): Add setlocale-null-unlocked. --- ChangeLog | 7 +++++++ lib/localename-unsafe.c | 5 ++++- modules/localename-unsafe | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 761f51bc36..487e5cf1dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-02-15 Bruno Haible + + localename-unsafe: Optimize. + * lib/localename-unsafe.c (gl_locale_name_posix_unsafe): Call + setlocale_null_unlocked instead of setlocale_null. + * modules/localename-unsafe (Depends-on): Add setlocale-null-unlocked. + 2024-02-15 Bruno Haible setlocale_null-unlocked: Add tests. diff --git a/lib/localename-unsafe.c b/lib/localename-unsafe.c index 5770d4a859..845ee92c31 100644 --- a/lib/localename-unsafe.c +++ b/lib/localename-unsafe.c @@ -3265,7 +3265,10 @@ gl_locale_name_posix_unsafe (int category, _GL_UNUSED const char *categoryname) /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'. On some systems this can be done by the 'setlocale' function itself. */ #if defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL - locname = setlocale_null (category); + /* All platforms for which HAVE_LOCALE_NULL is defined happen to have + SETLOCALE_NULL_ONE_MTSAFE defined to 1. Therefore it is OK, here, + to call setlocale_null_unlocked instead of setlocale_null. */ + locname = setlocale_null_unlocked (category); #else /* On other systems we ignore what setlocale reports and instead look at the environment variables directly. This is necessary diff --git a/modules/localename-unsafe b/modules/localename-unsafe index 3cb38a7c51..4b8ad0279b 100644 --- a/modules/localename-unsafe +++ b/modules/localename-unsafe @@ -24,6 +24,7 @@ strdup lock langinfo setlocale-null +setlocale-null-unlocked thread-optim configure.ac: -- 2.39.5