This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cpplib: double speed of comment skipping
- To: gcc-patches at gcc dot gnu dot org
- Subject: Re: cpplib: double speed of comment skipping
- From: Neil Booth <NeilB at earthling dot net>
- Date: Sat, 8 Apr 2000 10:02:02 +0900
- Cc: Zack Weinberg <zack at wolery dot cumb dot org>
- References: <E12diO1-0003Up-00@monkey.rosenet.ne.jp>
The previous patch had a problem tracking the position in the file for
issuing errors. This corrects it.
Neil.
* cpplex.c (skip_block_comment): replace GETC() with pointer
indirection and arithmetic.
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplex.c,v
retrieving revision 1.8
diff -u -p -r1.8 cpplex.c
--- cpplex.c 2000/04/06 07:56:14 1.8
+++ cpplex.c 2000/04/08 01:00:03
@@ -247,33 +247,37 @@ static void
skip_block_comment (pfile)
cpp_reader *pfile;
{
- int c, prev_c = -1;
long line, col;
+ const U_CHAR *limit, *cur;
FORWARD(1);
cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
- for (;;)
+ limit = CPP_BUFFER (pfile)->rlimit;
+ cur = CPP_BUFFER (pfile)->cur;
+
+ while (cur < limit)
{
- c = GETC ();
- if (c == EOF)
- {
- cpp_error_with_line (pfile, line, col, "unterminated comment");
- return;
- }
- else if (c == '\n' || c == '\r')
+ char c = *cur++;
+ if (c == '\n' || c == '\r')
{
/* \r cannot be a macro escape marker here. */
if (!ACTIVE_MARK_P (pfile))
- CPP_BUMP_LINE (pfile);
+ CPP_BUMP_LINE_CUR (pfile, cur);
}
- else if (c == '/' && prev_c == '*')
- return;
- else if (c == '*' && prev_c == '/'
+ else if (c == '/')
+ {
+ /* Avoid false positives for the comment's initial '*'. */
+ if (cur[-2] == '*' && cur - 2 >= CPP_BUFFER (pfile)->cur)
+ goto out;
+ }
+ else if (c == '*' && cur[-2] == '/'
&& CPP_OPTION (pfile, warn_comments))
cpp_warning (pfile, "`/*' within comment");
-
- prev_c = c;
}
+
+ cpp_error_with_line (pfile, line, col, "unterminated comment");
+ out:
+ CPP_BUFFER (pfile)->cur = cur;
}
/* Skip a C++/Chill line comment. We know it's a comment, and point
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpphash.h,v
retrieving revision 1.27
diff -u -p -r1.27 cpphash.h
--- cpphash.h 2000/04/06 07:56:14 1.27
+++ cpphash.h 2000/04/08 01:00:03
@@ -221,6 +221,10 @@ extern unsigned char _cpp_IStable[256];
#define CPP_BUMP_BUFFER_LINE(PBUF) ((PBUF)->lineno++,\
(PBUF)->line_base = (PBUF)->cur)
#define CPP_BUMP_LINE(PFILE) CPP_BUMP_BUFFER_LINE(CPP_BUFFER(PFILE))
+#define CPP_BUMP_BUFFER_LINE_CUR(PBUF, CUR) ((PBUF)->lineno++,\
+ (PBUF)->line_base = CUR)
+#define CPP_BUMP_LINE_CUR(PFILE, CUR) \
+ CPP_BUMP_BUFFER_LINE_CUR(CPP_BUFFER(PFILE), CUR)
#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
/* Are we in column 1 right now? Used mainly for -traditional handling