summaryrefslogtreecommitdiff
path: root/nasmlib.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-11 15:49:41 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-11 15:49:41 -0700
commitac8f8fcb27a063fbf7ec3ad3de18f6586e9e95b8 (patch)
treed4315e0d8a8c6d27d0883aa67461251ce4bbc59e /nasmlib.c
parent7b471fada8697930e4bdaff50fe51caa2798815f (diff)
downloadnasm-ac8f8fcb27a063fbf7ec3ad3de18f6586e9e95b8.tar.gz
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.
Diffstat (limited to 'nasmlib.c')
-rw-r--r--nasmlib.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/nasmlib.c b/nasmlib.c
index db4b2f17..9a49090e 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;