pr_lex.c:

rewrite PR_LexPunctuation to avoid looping. 6x speedup for that function
	according to gprof on customTF
configure.in:
	--enable-profile
This commit is contained in:
Bill Currie 2001-04-03 16:50:31 +00:00
parent 774d4ea1db
commit 2f2ba28bb7
2 changed files with 121 additions and 19 deletions

View file

@ -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.

View file

@ -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");