diff options
author | Ran Benita <ran234@gmail.com> | 2016-12-02 22:15:19 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2016-12-02 23:46:56 +0200 |
commit | b5586a6c4294b46eb23d1fc527ff63dcd27e23ac (patch) | |
tree | a567b29fe33c258006e6ec9b4d51a9acda4d0514 /src/utils.h | |
parent | 327364d277609600aa19aabd6dc55f2fc7dfb8cf (diff) | |
download | xorg-lib-libxkbcommon-b5586a6c4294b46eb23d1fc527ff63dcd27e23ac.tar.gz |
keysym: fix locale dependence in xkb_keysym_from_name()
We currently use strcasecmp, which is locale-dependent. In particular,
one well-known surprise even if restricted just ASCII input is found in
the tr_TR (Turkish) locale, see e.g.
https://msdn.microsoft.com/en-us/library/ms973919.aspx#stringsinnet20_topic5
We have known to avoid locale-dependent functions before, but in this
case, we forgot.
Fix it by implementing our own simple ASCII-only strcasecmp/strncasecmp.
Might have been possible to use strcasecmp_l() with the C locale, but
went the easy route.
Side advantage is that even this non-optimized version is faster than
the optimized libc one (__strcasecmp_l_sse42) since it doesn't need to
do the locale stuff. xkb_keysym_from_name(), which uses strcasecmp
heavily, becomes faster, and so for example Compose file parsing, which
uses xkb_keysym_from_name() heavily, becomes ~20% faster.
Resolves https://github.com/xkbcommon/libxkbcommon/issues/42
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/utils.h')
-rw-r--r-- | src/utils.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/utils.h b/src/utils.h index d63d23a..cb98e8e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -29,7 +29,6 @@ #include <stdbool.h> #include <stdio.h> #include <string.h> -#include <strings.h> #include "darray.h" @@ -44,6 +43,15 @@ switch (0) { case 0: case (expr): ; } \ } while (0) +char +to_lower(char c); + +int +istrcmp(const char *a, const char *b); + +int +istrncmp(const char *a, const char *b, size_t n); + static inline bool streq(const char *s1, const char *s2) { @@ -61,13 +69,13 @@ streq_not_null(const char *s1, const char *s2) static inline bool istreq(const char *s1, const char *s2) { - return strcasecmp(s1, s2) == 0; + return istrcmp(s1, s2) == 0; } static inline bool istreq_prefix(const char *s1, const char *s2) { - return strncasecmp(s1, s2, strlen(s1)) == 0; + return istrncmp(s1, s2, strlen(s1)) == 0; } static inline char * |