From b96c3bcd66f43d6176a9d5dff69d9f5aeb697a62 Mon Sep 17 00:00:00 2001 From: dt Date: Sun, 12 Sep 1999 21:15:28 +0000 Subject: [PATCH] __collate_substitute() do something non-trivial only for German. For everyone else, it is equivalent to strdup(). So, we will check if the substitution tables are trivial at the load time, and possibly save 2 calls to __collate_substitute() in strcoll(). Still, __collate_substitute() should not exist. --- lib/libc/locale/collate.c | 15 +++++++++++++-- lib/libc/locale/collate.h | 3 ++- lib/libc/string/strcoll.c | 13 ++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index a73e4f1bcf5..cfa7cfe7e17 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -38,6 +38,7 @@ #include "setlocale.h" int __collate_load_error = 1; +int __collate_substitute_nontrivial; char __collate_version[STR_LEN]; u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN]; struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1]; @@ -59,7 +60,7 @@ __collate_load_tables(encoding) { char buf[PATH_MAX]; FILE *fp; - int save_load_error; + int i, save_load_error; save_load_error = __collate_load_error; __collate_load_error = 1; @@ -95,6 +96,16 @@ __collate_load_tables(encoding) fp); fclose(fp); __collate_load_error = 0; + + __collate_substitute_nontrivial = 0; + for (i = 0; i < UCHAR_MAX + 1; i++) { + if (__collate_substitute_table[i][0] != i || + __collate_substitute_table[i][1] != 0) { + __collate_substitute_nontrivial = 1; + break; + } + } + return 0; } @@ -128,7 +139,7 @@ __collate_substitute(s) void __collate_lookup(t, len, prim, sec) - u_char *t; + const u_char *t; int *len, *prim, *sec; { struct __collate_st_chain_pri *p2; diff --git a/lib/libc/locale/collate.h b/lib/libc/locale/collate.h index 23a87b7e0a7..ae6317c3abe 100644 --- a/lib/libc/locale/collate.h +++ b/lib/libc/locale/collate.h @@ -47,6 +47,7 @@ struct __collate_st_chain_pri { }; extern int __collate_load_error; +extern int __collate_substitute_nontrivial; extern char __collate_version[STR_LEN]; extern u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN]; extern struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1]; @@ -56,7 +57,7 @@ __BEGIN_DECLS u_char *__collate_strdup __P((u_char *)); u_char *__collate_substitute __P((const u_char *)); int __collate_load_tables __P((char *)); -void __collate_lookup __P((u_char *, int *, int *, int *)); +void __collate_lookup __P((const u_char *, int *, int *, int *)); int __collate_range_cmp __P((int, int)); #ifdef COLLATE_DEBUG void __collate_print_tables __P((void)); diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c index b4631a1f00a..5213cf84d97 100644 --- a/lib/libc/string/strcoll.c +++ b/lib/libc/string/strcoll.c @@ -36,15 +36,22 @@ strcoll(s, s2) const char *s, *s2; { int len, len2, prim, prim2, sec, sec2, ret, ret2; - char *tt, *t, *tt2, *t2; + const char *t, *t2; + char *tt, *tt2; if (__collate_load_error) return strcmp(s, s2); len = len2 = 1; ret = ret2 = 0; - tt = t = __collate_substitute(s); - tt2 = t2 = __collate_substitute(s2); + if (__collate_substitute_nontrivial) { + t = tt = __collate_substitute(s); + t2 = tt2 = __collate_substitute(s2); + } else { + tt = tt2 = NULL; + t = s; + t2 = s2; + } while(*t && *t2) { prim = prim2 = 0; while(*t && !prim) { -- 2.45.0