This patch implements another aforementioned optimization: The function should_remove_ampm uses the locale name directly and stops accessing it before the function returns.
2024-02-15 Bruno Haible <br...@clisp.org> nstrftime, fprintftime: Optimize. * lib/strftime.c (should_remove_ampm): Call gl_locale_name_unsafe instead of gl_locale_name. * modules/nstrftime (Depends-on): Remove localename. Add localename-unsafe. diff --git a/lib/strftime.c b/lib/strftime.c index c7256c3d35..128176cad4 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -401,7 +401,7 @@ should_remove_ampm (void) lt lv mg mhr mi mk mn ms mt nb nds nhn nl nn nr nso oc os pap pl pt ro ru rw sah sc se sgs sk sl sm sr ss st su sv szl tg tk tn ts tt ug uk unm uz ve wae wo xh zu */ - const char *loc = gl_locale_name (LC_TIME, "LC_TIME"); + const char *loc = gl_locale_name_unsafe (LC_TIME, "LC_TIME"); bool remove_ampm = false; switch (loc[0]) { diff --git a/modules/nstrftime b/modules/nstrftime index 77a8594c4c..c5ab2710c0 100644 --- a/modules/nstrftime +++ b/modules/nstrftime @@ -15,7 +15,7 @@ errno extensions intprops libc-config -localename +localename-unsafe stdbool stdckdint time_rz