This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
speeding up localedef
- To: libc-alpha at sources dot redhat dot com
- Subject: speeding up localedef
- From: Bruno Haible <haible at ilog dot fr>
- Date: Mon, 28 Aug 2000 11:51:27 +0200 (CEST)
Currently, when creating an UTF-8 locale, "localedef" runs for ca. 2:40
minutes, 2 minutes spent in collate_finish() (LC_COLLATE locale) and 40 sec
spent in find_idx() (LC_CTYPE locale).
Here is a patch to kill these 40 seconds. localedef will allocate 256 KB
more memory, but it will be much faster. The other 2 minustes go away
with my next patch.
2000-08-27 Bruno Haible <haible@clisp.cons.org>
* locale/programs/ld-ctype.c (MAX_CHARNAMES_IDX): New macro.
(locale_ctype_t): New charnames_idx field.
(ctype_startup): Initialize charnames_idx field.
(find_idx): Speed up dramatically by using charnames_idx inverse table.
*** glibc-20000826/locale/programs/ld-ctype.c.bak Fri Aug 25 23:52:58 2000
--- glibc-20000826/locale/programs/ld-ctype.c Sun Aug 27 15:27:38 2000
***************
*** 112,117 ****
--- 112,120 ----
uint32_t *charnames;
size_t charnames_max;
size_t charnames_act;
+ /* An index lookup table, to speedup find_idx. */
+ #define MAX_CHARNAMES_IDX 0x10000
+ uint32_t *charnames_idx;
struct repertoire_t *repertoire;
***************
*** 253,258 ****
--- 256,265 ----
for (cnt = 0; cnt < 256; ++cnt)
ctype->charnames[cnt] = cnt;
ctype->charnames_act = 256;
+ ctype->charnames_idx =
+ (uint32_t *) xmalloc (MAX_CHARNAMES_IDX * sizeof (uint32_t));
+ for (cnt = 0; cnt < MAX_CHARNAMES_IDX; ++cnt)
+ ctype->charnames_idx[cnt] = ~((uint32_t) 0);
/* Fill character class information. */
ctype->last_class_char = ILLEGAL_CHAR_VALUE;
***************
*** 1299,1307 ****
if (idx < 256)
return table == NULL ? NULL : &(*table)[idx];
! for (cnt = 256; cnt < ctype->charnames_act; ++cnt)
! if (ctype->charnames[cnt] == idx)
! break;
/* We have to distinguish two cases: the name is found or not. */
if (cnt == ctype->charnames_act)
--- 1306,1328 ----
if (idx < 256)
return table == NULL ? NULL : &(*table)[idx];
! /* If idx is in the usual range, use the charnames_idx lookup table
! instead of the slow search loop. */
! if (idx < MAX_CHARNAMES_IDX)
! {
! if (ctype->charnames_idx[idx] != ~((uint32_t) 0))
! /* Found. */
! cnt = ctype->charnames_idx[idx];
! else
! /* Not found. */
! cnt = ctype->charnames_act;
! }
! else
! {
! for (cnt = 256; cnt < ctype->charnames_act; ++cnt)
! if (ctype->charnames[cnt] == idx)
! break;
! }
/* We have to distinguish two cases: the name is found or not. */
if (cnt == ctype->charnames_act)
***************
*** 1315,1320 ****
--- 1336,1343 ----
sizeof (uint32_t) * ctype->charnames_max);
}
ctype->charnames[ctype->charnames_act++] = idx;
+ if (idx < MAX_CHARNAMES_IDX)
+ ctype->charnames_idx[idx] = cnt;
}
if (table == NULL)