This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cpplib: double speed of comment skipping


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]