From cc85b927cdc1a4dad3217842215903a45044fc43 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sat, 22 Jun 2013 00:22:08 -0400 Subject: Create a character map to use for locating stop-points in strings. In various places we were passing flags and characters to compare, then using complex conditionals to see where to stop in string searches. Performance numbers reveal that we were spending as much as 23% of our processing time in these functions, most of it in the comparison lines. Instead create a character map and use a single bitwise comparison to determine if this is any one of the stop characters. --- dir.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index 87b8eb3..5681275 100644 --- a/dir.c +++ b/dir.c @@ -16,6 +16,7 @@ this program. If not, see . */ #include "makeint.h" #include "hash.h" +#include "dep.h" #ifdef HAVE_DIRENT_H # include @@ -84,21 +85,21 @@ dosify (const char *filename) df = dos_filename; /* First, transform the name part. */ - for (i = 0; *filename != '\0' && i < 8 && *filename != '.'; ++i) + for (i = 0; i < 8 && ! STOP_SET (*filename, MAP_DOT|MAP_NUL); ++i) *df++ = tolower ((unsigned char)*filename++); /* Now skip to the next dot. */ - while (*filename != '\0' && *filename != '.') + while (! STOP_SET (*filename, MAP_DOT|MAP_NUL)) ++filename; if (*filename != '\0') { *df++ = *filename++; - for (i = 0; *filename != '\0' && i < 3 && *filename != '.'; ++i) + for (i = 0; i < 3 && ! STOP_SET (*filename, MAP_DOT|MAP_NUL); ++i) *df++ = tolower ((unsigned char)*filename++); } /* Look for more dots. */ - while (*filename != '\0' && *filename != '.') + while (! STOP_SET (*filename, MAP_DOT|MAP_NUL)) ++filename; if (*filename == '.') return filename; -- cgit v1.2.3