scanner-utils: optimize one-line comments

Compose files have a lot of those.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2014-10-07 23:42:08 +03:00
parent 8d58e250b0
commit 8a0acf2c67
4 changed files with 12 additions and 3 deletions

View File

@ -134,7 +134,7 @@ skip_more_whitespace_and_comments:
/* Skip comments. */
if (chr(s, '#')) {
while (!eof(s) && !eol(s)) next(s);
skip_to_eol(s);
goto skip_more_whitespace_and_comments;
}

View File

@ -102,6 +102,15 @@ eol(struct scanner *s)
return peek(s) == '\n';
}
static inline void
skip_to_eol(struct scanner *s)
{
const char *nl = memchr(s->s + s->pos, '\n', s->len - s->pos);
const size_t new_pos = nl ? (size_t) (nl - s->s) : s->len;
s->column += new_pos - s->pos;
s->pos = new_pos;
}
static inline char
next(struct scanner *s)
{

View File

@ -85,7 +85,7 @@ skip_more_whitespace_and_comments:
/* Skip comments. */
if (lit(s, "//")) {
while (!eof(s) && !eol(s)) next(s);
skip_to_eol(s);
}
/* New line. */

View File

@ -69,7 +69,7 @@ skip_more_whitespace_and_comments:
/* Skip comments. */
if (lit(s, "//") || chr(s, '#')) {
while (!eof(s) && !eol(s)) next(s);
skip_to_eol(s);
goto skip_more_whitespace_and_comments;
}