From ac8f8fcb27a063fbf7ec3ad3de18f6586e9e95b8 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 11 Jun 2008 15:49:41 -0700 Subject: Use an explicit table for tolower() to avoid a function call On some platforms, tolower() is implemented as a function call, in order to handle locale support. We never change locales, so can the result of tolower() into a table, so we don't have to sit through the function call every time. ~1.3% overall performance improvement on a macro-heavy benchmark under Linux x86-64. --- nasmlib.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'nasmlib.c') diff --git a/nasmlib.c b/nasmlib.c index db4b2f1..9a49090 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -25,6 +25,21 @@ efunc nasm_malloc_error; /* Exported for the benefit of vsnprintf.c */ static FILE *logfp; #endif +/* + * Prepare a table of tolower() results. This avoids function calls + * on some platforms. + */ + +unsigned char nasm_tolower_tab[256]; + +void tolower_init(void) +{ + int i; + + for (i = 0; i < 256; i++) + nasm_tolower_tab[i] = tolower(i); +} + void nasm_set_malloc_error(efunc error) { nasm_malloc_error = error; @@ -192,8 +207,8 @@ int nasm_memicmp(const char *s1, const char *s2, size_t n) int d; while (n--) { - c1 = tolower(*s1++); - c2 = tolower(*s2++); + c1 = nasm_tolower(*s1++); + c2 = nasm_tolower(*s2++); d = c1-c2; if (d) return d; -- cgit v1.2.3