[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
localcharset: optimize code for native Windows.
From: |
Bruno Haible |
Subject: |
localcharset: optimize code for native Windows. |
Date: |
Tue, 17 Dec 2019 15:06:50 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; ) |
The localcharset code for native Windows first fetches
setlocale (LC_ALL, NULL), then notices "oh, this is not what we want",
then fetches setlocale (LC_CTYPE, NULL).
Example:
LC_CTYPE => "English_United States.1252"
LC_NUMERIC => "French_France.1252"
LC_TIME => "German_Germany.1252"
LC_ALL => "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=French_France.1252;LC_TIME=German_Germany.1252"
This can be optimized.
2019-12-17 Bruno Haible <address@hidden>
localcharset: Optimize code for native Windows.
* lib/localcharset.c (locale_charset): Don't both calling
setlocale (LC_ALL, NULL) since we're not interested in its result.
diff --git a/lib/localcharset.c b/lib/localcharset.c
index 8d17e4c..126f085 100644
--- a/lib/localcharset.c
+++ b/lib/localcharset.c
@@ -901,27 +901,20 @@ locale_charset (void)
'setlocale' call specified. So we use it as a last resort, in
case the string returned by 'setlocale' doesn't specify the
codepage. */
- char *current_locale = setlocale (LC_ALL, NULL);
- char *pdot;
+ char *current_locale = setlocale (LC_CTYPE, NULL);
+ char *pdot = strrchr (current_locale, '.');
- /* If they set different locales for different categories,
- 'setlocale' will return a semi-colon separated list of locale
- values. To make sure we use the correct one, we choose LC_CTYPE. */
- if (strchr (current_locale, ';'))
- current_locale = setlocale (LC_CTYPE, NULL);
-
- pdot = strrchr (current_locale, '.');
if (pdot && 2 + strlen (pdot + 1) + 1 <= sizeof (buf))
sprintf (buf, "CP%s", pdot + 1);
else
{
/* The Windows API has a function returning the locale's codepage as a
- number: GetACP().
- When the output goes to a console window, it needs to be provided in
- GetOEMCP() encoding if the console is using a raster font, or in
- GetConsoleOutputCP() encoding if it is using a TrueType font.
- But in GUI programs and for output sent to files and pipes, GetACP()
- encoding is the best bet. */
+ number: GetACP().
+ When the output goes to a console window, it needs to be provided in
+ GetOEMCP() encoding if the console is using a raster font, or in
+ GetConsoleOutputCP() encoding if it is using a TrueType font.
+ But in GUI programs and for output sent to files and pipes, GetACP()
+ encoding is the best bet. */
sprintf (buf, "CP%u", GetACP ());
}
/* For a locale name such as "French_France.65001", in Windows 10,
- localcharset: optimize code for native Windows.,
Bruno Haible <=