On Fri, Feb 23, 2018 at 12:27:14PM -0800, William Ahern wrote:
> The routine skip_empty_lines_and_read_char() is an optimization to skip over
> blocks of comment lines. When it reads an unescaped '#' it uses the helper
> routine skip_to_end_of_line(). But skip_to_end_of_line() doesn't fold lines
> as it should and like its parent caller does. (See patch at end of message.)

FWIW, I meant skip_to_end_of_line() doesn't _unfold_ lines as it should. I
rephrased the subject line in case anyone ignored this patch thinking I was
submitting a patch to reformat comment lines in lowparse.c itself.

Is there any interest in accepting this patch? Would there be any interest
in a patch which rewrote skip_empty_lines_and_read_char itself? I think it
could be substantially simplified using the same, simple state machine I
used to fix skip_to_end_of_lines. The performance benefit of the current
approach seems dubious relative to the complexity, and especially
considering its (wrongly) predicated on the ability to avoid parsing escape
sequences past '#' comments without violating the syntax rules. I just
figured it wasn't worth fixing what wasn't broken as long as I could easily
fix what was broken.

<snip>
> Index: lowparse.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/make/lowparse.c,v
> retrieving revision 1.35
> diff -u -r1.35 lowparse.c
> --- lowparse.c        21 Oct 2016 16:12:38 -0000      1.35
> +++ lowparse.c        23 Feb 2018 20:02:59 -0000
> @@ -247,20 +247,21 @@
>  static int
>  skip_to_end_of_line(void)
>  {
> -     if (current->F) {
> -             if (current->end - current->ptr > 1)
> -                     current->ptr = current->end - 1;
> -             if (*current->ptr == '\n')
> -                     return *current->ptr++;
> -             return EOF;
> -     } else {
> -             int c;
> +     int escaped = 0, c;
>  
> -             do {
> -                     c = read_char();
> -             } while (c != '\n' && c != EOF);
> -             return c;
> +     while (EOF != (c = read_char())) {
> +             if (escaped) {
> +                     if (c == '\n')
> +                             current->origin.lineno++;
> +                     escaped = 0;
> +             } else if (c == '\\') {
> +                     escaped = 1;
> +             } else if (c == '\n') {
> +                     break;
> +             }
>       }
> +
> +     return c;
>  }
>  
>  

Reply via email to