Discussion:
[PATCH V2] localcharset: short-circuit the search for an alias on a Mac
Benno Schulenberg
2018-04-21 09:08:08 UTC
Permalink
* lib/localcharset.c (get_charset_aliases): Add a tautological
UTF-8 entry to speed up the search for this case.

Most machines default to a UTF-8 locale nowadays, so begin the
list of aliases with a dummy UTF-8 entry so it will be found
immediately and a time-consuming search through the rest of
the list is avoided.
---
ChangeLog | 10 ++++++++++
lib/localcharset.c | 3 ++-
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index f5752a217..1c6f32294 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-04-21 Benno Schulenberg <***@telfort.nl> (tiny change)
+
+ localcharset: short-circuit the search for an alias on a Mac
+ * lib/localcharset.c (get_charset_aliases): Add a tautological
+ UTF-8 entry to speed up the search for this case.
+ Most machines default to a UTF-8 locale nowadays, so begin the
+ list of aliases with a dummy UTF-8 entry so it will be found
+ immediately and a time-consuming search through the rest of
+ the list is avoided.
+
2018-04-11 Paul Eggert <***@cs.ucla.edu>

fts: add comment
diff --git a/lib/localcharset.c b/lib/localcharset.c
index a73d6bdd1..66f6dacc0 100644
--- a/lib/localcharset.c
+++ b/lib/localcharset.c
@@ -263,7 +263,8 @@ get_charset_aliases (void)
/* To avoid the trouble of installing a file that is shared by many
GNU packages -- many packaging systems have problems with this --,
simply inline the aliases here. */
- cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
+ cp = "UTF-8" "\0" "UTF-8" "\0"
+ "ISO8859-1" "\0" "ISO-8859-1" "\0"
"ISO8859-2" "\0" "ISO-8859-2" "\0"
"ISO8859-4" "\0" "ISO-8859-4" "\0"
"ISO8859-5" "\0" "ISO-8859-5" "\0"
--
2.16.3
Bruno Haible
2018-04-21 10:41:57 UTC
Permalink
Hi Benno,
Post by Benno Schulenberg
* lib/localcharset.c (get_charset_aliases): Add a tautological
UTF-8 entry to speed up the search for this case.
Most machines default to a UTF-8 locale nowadays, so begin the
list of aliases with a dummy UTF-8 entry so it will be found
immediately and a time-consuming search through the rest of
the list is avoided.
Thanks, applied.

I added a comment.
Explanations about the code belong in the code, as comments, IMO.
Readers of the code should not be forced to constantly refer to
ChangeLog entries and commit messages in order to understand the code.

Bruno
Benno Schulenberg
2018-04-21 11:23:53 UTC
Permalink
Hi Bruno,
Post by Bruno Haible
Thanks, applied.
(For some background: a bug reporter found that on a Mac lots of
time would be spent in locale_charset() when nano called wcwidth():
https://savannah.gnu.org/bugs/?53562#comment16.)
Post by Bruno Haible
I added a comment.
Explanations about the code belong in the code, as comments, IMO.
Readers of the code should not be forced to constantly refer to
ChangeLog entries and commit messages in order to understand the code.
True. Much better this way. Thanks.

Benno

Loading...