This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
cpplib speed hack
- To: egcs-patches at egcs dot cygnus dot com, brolley at cygnus dot com
- Subject: cpplib speed hack
- From: Zack Weinberg <zack at rabi dot columbia dot edu>
- Date: Fri, 16 Apr 1999 23:18:16 -0400
cpplib contains two functions, skip_rest_of_line and
copy_rest_of_line, which do what they sound like. Currently
skip_rest_of_line calls copy_rest_of_line and then throws away the
text that's been copied. Profiling indicates that more than 75% of
calls to c_r_o_l are either from s_r_o_l or skip_if_group, which also
copies the text only to discard it.
By rewriting s_r_o_l to do the forward scan itself, we get about 5%
performance improvement compiling GNU libc, at the cost of some code
duplication.
(old) 1:44:41 - 5049.70 user, 538.54 system, 88% cpu
(new) 1:39:12 - 4986.01 user, 526.64 system, 92% cpu
I am not sure why system time is reduced. It is probably unrelated.
This patch is relative to the previous patch for cpplib (line numbering
bugfix) but should apply cleanly-but-offset without it.
zw
1999-04-16 23:14 -0400 Zack Weinberg <zack@rabi.phys.columbia.edu>
* cpplib.c (skip_rest_of_line): Do the forward scan here
instead of calling copy_rest_of_line.
(skip_if_group): Call skip_rest_of_line not copy_rest_of_line.
--- cpplib.c.prev Thu Apr 15 20:51:30 1999
+++ cpplib.c Fri Apr 16 23:05:12 1999
@@ -476,17 +476,54 @@
}
}
-/* FIXME: It is almost definitely a performance win to make this do
- the scan itself. >75% of calls to copy_r_o_l are from here or
- skip_if_group, which means the common case is to copy stuff into the
- token_buffer only to discard it. */
+/* Read the rest of the current line and discard it. */
+
void
skip_rest_of_line (pfile)
cpp_reader *pfile;
{
- long old = CPP_WRITTEN (pfile);
- copy_rest_of_line (pfile);
- CPP_SET_WRITTEN (pfile, old);
+ long here = CPP_WRITTEN (pfile);
+ for (;;)
+ {
+ int c = GETC();
+ switch (c)
+ {
+ case '\n':
+ FORWARD(-1);
+ case EOF:
+ return;
+
+ case '\r':
+ if (!CPP_BUFFER (pfile)->has_escapes)
+ CPP_BUFFER (pfile)->lineno++;
+ break;
+
+ case '\'':
+ case '\"':
+ parse_string (pfile, c);
+ CPP_SET_WRITTEN (pfile, here);
+ break;
+
+ case '/':
+ if (PEEKC() == '*' && CPP_TRADITIONAL (pfile))
+ {
+ CPP_PUTS (pfile, "/**/", 4);
+ skip_comment (pfile, c);
+ break;
+ }
+ /* else fall through */
+ case '-':
+ c = skip_comment (pfile, c);
+ break;
+
+ case '\f':
+ case '\v':
+ if (CPP_PEDANTIC (pfile))
+ cpp_pedwarn (pfile, "%s in preprocessing directive",
+ c == '\f' ? "formfeed" : "vertical tab");
+ break;
+ }
+ }
}
/* Handle a possible # directive.
@@ -1877,7 +1859,6 @@
int c;
IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
U_CHAR *beg_of_line;
- long old_written;
if (CPP_OPTIONS (pfile)->output_conditionals)
{
@@ -1886,8 +1867,6 @@
output_line_command (pfile, same_file);
}
- old_written = CPP_WRITTEN (pfile);
-
for (;;)
{
beg_of_line = CPP_BUFFER (pfile)->cur;
@@ -1917,10 +1896,7 @@
copy_rest_of_line (pfile);
}
else
- {
- copy_rest_of_line (pfile);
- CPP_SET_WRITTEN (pfile, old_written); /* discard it */
- }
+ skip_rest_of_line (pfile);
c = GETC();
if (c == EOF)