bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

localename: optimize code for native Windows


From: Bruno Haible
Subject: localename: optimize code for native Windows
Date: Wed, 18 Dec 2019 15:08:15 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; )

This piece of code in localename.c

      const char *locname = setlocale (category, NULL);
      LCID lcid;

      /* If CATEGORY is LC_ALL, the result might be a semi-colon
        separated list of locales.  We need only one, so we take the
        one corresponding to LC_CTYPE, as the most important for
        character translations.  */
      if (category == LC_ALL && strchr (locname, ';'))
        locname = setlocale (LC_CTYPE, NULL);

can be optimized to

      const char *locname = setlocale (category == LC_ALL ? LC_CTYPE : 
category, NULL);

using the same reasoning as in
<https://lists.gnu.org/archive/html/bug-gnulib/2019-12/msg00129.html>.

Even better: This piece of code is in a place where category cannot be LC_ALL
(per the specification in localename.h). Thus it can be simplified even further.


2019-12-18  Bruno Haible  <address@hidden>

        localename: Optimize code for native Windows.
        * lib/localename.c (gl_locale_name_posix): Remove handling of LC_ALL
        category (not allowed here).

diff --git a/lib/localename.c b/lib/localename.c
index b6b94c2..d88743e 100644
--- a/lib/localename.c
+++ b/lib/localename.c
@@ -3242,19 +3242,11 @@ gl_locale_name_posix (int category, const char 
*categoryname)
   if (LC_MIN <= category && category <= LC_MAX)
     {
       const char *locname = setlocale (category, NULL);
-      LCID lcid;
-
-      /* If CATEGORY is LC_ALL, the result might be a semi-colon
-        separated list of locales.  We need only one, so we take the
-        one corresponding to LC_CTYPE, as the most important for
-        character translations.  */
-      if (category == LC_ALL && strchr (locname, ';'))
-        locname = setlocale (LC_CTYPE, NULL);
 
       /* Convert locale name to LCID.  We don't want to use
          LocaleNameToLCID because (a) it is only available since Vista,
          and (b) it doesn't accept locale names returned by 'setlocale'.  */
-      lcid = get_lcid (locname);
+      LCID lcid = get_lcid (locname);
 
       if (lcid > 0)
         return gl_locale_name_from_win32_LCID (lcid);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]