From 2f2ba28bb7a7a8d3d50b5c0da515941dfec4dc4f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 3 Apr 2001 16:50:31 +0000 Subject: [PATCH] pr_lex.c: rewrite PR_LexPunctuation to avoid looping. 6x speedup for that function according to gprof on customTF configure.in: --enable-profile --- tools/qfcc/configure.in | 13 ++++ tools/qfcc/source/pr_lex.c | 127 +++++++++++++++++++++++++++++++------ 2 files changed, 121 insertions(+), 19 deletions(-) diff --git a/tools/qfcc/configure.in b/tools/qfcc/configure.in index 34f3f6ba1..664f3f987 100644 --- a/tools/qfcc/configure.in +++ b/tools/qfcc/configure.in @@ -51,6 +51,19 @@ AC_HEADER_STDC AC_CHECK_HEADERS(unistd.h) dnl Checks for typedefs, structures, and compiler characteristics. +AC_ARG_ENABLE(profile, + [ --enable-profile compile with profiling (for development)], + profile=$enable_profile +) +if test "x$profile" = xyes; then + BUILD_TYPE="$BUILD_TYPE Profile" + if test "x$GCC" = xyes; then + CFLAGS="$(echo $CFLAGS | sed -e 's/-fomit-frame-pointer//g') -pg" + LDFLAGS="$LDFLAGS -pg" + else + CFLAGS="$CFLAGS -p" + fi +fi dnl Checks for library functions. diff --git a/tools/qfcc/source/pr_lex.c b/tools/qfcc/source/pr_lex.c index 6340f33df..03f11f34c 100644 --- a/tools/qfcc/source/pr_lex.c +++ b/tools/qfcc/source/pr_lex.c @@ -49,11 +49,6 @@ char pr_immediate_string[2048]; int pr_error_count; -char *pr_punctuation[] = { // longer symbols first to avoid partial matches - "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*", "/", "(", ")", "-", - "+", "=", "[", "]", "{", "}", "...", ".", "<", ">", "#", "&", "|", NULL -}; - // simple types. function types are dynamically allocated type_t type_void = { ev_void, &def_void }; type_t type_string = { ev_string, &def_string }; @@ -243,23 +238,117 @@ PR_LexName (void) void PR_LexPunctuation (void) { - int i; - int len; - char *p; + char *p = 0; + int len = 1; pr_token_type = tt_punct; - for (i = 0; (p = pr_punctuation[i]) != NULL; i++) { - len = strlen (p); - if (!strncmp (p, pr_file_p, len)) { - strcpy (pr_token, p); - if (p[0] == '{') - pr_bracelevel++; - else if (p[0] == '}') - pr_bracelevel--; - pr_file_p += len; - return; - } + switch (pr_file_p[0]) { + case '&': + if (pr_file_p[1] == '&') { + p = "&&"; + len = 2; + } else { + p = "&"; + } + break; + case '|': + if (pr_file_p[1] == '|') { + p = "||"; + len = 2; + } else { + p = "|"; + } + break; + case '<': + if (pr_file_p[1] == '=') { + p = "<="; + len = 2; + } else { + p = "<"; + } + break; + case '>': + if (pr_file_p[1] == '=') { + p = ">="; + len = 2; + } else { + p = ">"; + } + break; + case '=': + if (pr_file_p[1] == '=') { + p = "=="; + len = 2; + } else { + p = "="; + } + break; + case '!': + if (pr_file_p[1] == '=') { + p = "!="; + len = 2; + } else { + p = "!"; + } + break; + case ';': + p = ";"; + break; + case ',': + p = ","; + break; + case '*': + p = "*"; + break; + case '/': + p = "/"; + break; + case '(': + p = "("; + break; + case ')': + p = ")"; + break; + case '-': + p = "-"; + break; + case '+': + p = "+"; + break; + case '[': + p = "["; + break; + case ']': + p = "]"; + break; + case '{': + p = "{"; + break; + case '}': + p = "}"; + break; + case '.': + if (pr_file_p[1] == '.' && pr_file_p[2] == '.') { + p = "..."; + len = 3; + } else { + p = "."; + } + break; + case '#': + p = "#"; + break; + } + + if (p) { + strcpy (pr_token, p); + if (p[0] == '{') + pr_bracelevel++; + else if (p[0] == '}') + pr_bracelevel--; + pr_file_p += len; + return; } PR_ParseError ("Unknown punctuation");