]> Savannah Git Hosting - gnulib.git/commitdiff
localename: Speed up lookup of the LC_MESSAGES name on AIX ≥ 7.2.
authorBruno Haible <bruno@clisp.org>
Thu, 15 Feb 2024 15:00:59 +0000 (16:00 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 15 Feb 2024 18:42:14 +0000 (19:42 +0100)
* 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
lib/localename.c
m4/intl-thread-locale.m4

index 365a8d07e0e6923e880ba9f2dae159f429ce111b..4007567028d9080d54e1c91efb45271d9464c6c5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-02-15  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        localename: Add more comments.
index 1bdc73f1cbf9e23cf5c63b13e8776d50965d0920..f6879ac33000b85c5b3221a7871d5683aaf694c1 100644 (file)
@@ -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;
index 9710cb6d849ee19d462f6761216b147c1180c701..63efc44fbc342f645b54729d74fd81a7677ec7a4 100644 (file)
@@ -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 @@ int main ()
   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 @@ int main ()
       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 <locale.h>
+              /* Include <sys/localedef.h>, which defines __locale_t.  */
+              #include <stdlib.h>
+              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 @@ int main ()
   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