From 276f74abae91dc777e279888634d272089f0562f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 15 Feb 2024 16:00:59 +0100 Subject: [PATCH 03/12] =?UTF-8?q?localename:=20Speed=20up=20lookup=20of=20?= =?UTF-8?q?the=20LC=5FMESSAGES=20name=20on=20AIX=20=E2=89=A5=207.2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * m4/intl-thread-locale.m4 (gt_INTL_THREAD_LOCALE_NAME): On AIX, test for the 'locale_name' member. * lib/localename.c (get_locale_t_name): For the LC_MESSAGES category, use the 'locale_name' member if available. --- ChangeLog | 8 ++++++++ lib/localename.c | 18 +++++++++++++----- m4/intl-thread-locale.m4 | 26 +++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 365a8d07e0..4007567028 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-02-15 Bruno Haible + + localename: Speed up lookup of the LC_MESSAGES name on AIX ≥ 7.2. + * m4/intl-thread-locale.m4 (gt_INTL_THREAD_LOCALE_NAME): On AIX, test + for the 'locale_name' member. + * lib/localename.c (get_locale_t_name): For the LC_MESSAGES category, + use the 'locale_name' member if available. + 2024-02-15 Bruno Haible localename: Add more comments. diff --git a/lib/localename.c b/lib/localename.c index 1bdc73f1cb..f6879ac330 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -1,12 +1,12 @@ /* Determine name of the currently selected locale. Copyright (C) 1995-2024 Free Software Foundation, Inc. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. @@ -2747,6 +2747,14 @@ get_locale_t_name (int category, locale_t locale) } else { +# if HAVE_AIX72_LOCALES + if (category == LC_MESSAGES) + { + const char *name = ((__locale_t) locale)->locale_name; + if (name != NULL) + return struniq (name); + } +# endif /* Look up the names in the hash table. */ size_t hashcode = locale_hash_function (locale); size_t slot = hashcode % LOCALE_HASH_TABLE_SIZE; diff --git a/m4/intl-thread-locale.m4 b/m4/intl-thread-locale.m4 index 9710cb6d84..63efc44fbc 100644 --- a/m4/intl-thread-locale.m4 +++ b/m4/intl-thread-locale.m4 @@ -1,4 +1,4 @@ -# intl-thread-locale.m4 serial 11 +# intl-thread-locale.m4 serial 12 dnl Copyright (C) 2015-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -130,7 +130,8 @@ AC_DEFUN([gt_INTL_THREAD_LOCALE_NAME] dnl requires the gnulib overrides of 'newlocale', 'duplocale', 'freelocale', dnl which is a problem for GNU libunistring. Therefore try hard to avoid dnl enabling this code! - dnl Expected result: HAVE_NAMELESS_LOCALES is defined on AIX. + dnl Expected result: HAVE_NAMELESS_LOCALES is defined on AIX, + dnl and HAVE_AIX72_LOCALES is defined on AIX ≥ 7.2. gt_nameless_locales=no case "$host_os" in dnl It's needed on AIX 7.2. @@ -138,6 +139,25 @@ AC_DEFUN([gt_INTL_THREAD_LOCALE_NAME] gt_nameless_locales=yes AC_DEFINE([HAVE_NAMELESS_LOCALES], [1], [Define if the locale_t type does not contain the name of each locale category.]) + dnl In AIX ≥ 7.2, a locale contains at least the name of the LC_MESSSAGES + dnl category (fix of defect 823926). + AC_CACHE_CHECK([for AIX locales with LC_MESSAGES name], + [gt_cv_locale_aix72], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #include + /* Include , which defines __locale_t. */ + #include + locale_t x; + ]], + [[return ((__locale_t) x)->locale_name[0];]])], + [gt_cv_locale_aix72=yes], + [gt_cv_locale_aix72=no]) + ]) + if test $gt_cv_locale_aix72 = yes; then + AC_DEFINE([HAVE_AIX72_LOCALES], [1], + [Define if the __locale_t type contains the name of the LC_MESSAGES category.]) + fi ;; esac @@ -150,7 +170,7 @@ AC_DEFUN([gt_INTL_THREAD_LOCALE_NAME] if test $gt_working_uselocale = yes && test $gt_fake_locales = no; then gt_good_uselocale=yes AC_DEFINE([HAVE_GOOD_USELOCALE], [1], - [Define if the uselocale exists, may be safely called, and returns sufficient information.]) + [Define if the uselocale function exists, may be safely called, and returns sufficient information.]) else gt_good_uselocale=no fi -- 2.34.1