scanner-utils: optimize one-line comments
Compose files have a lot of those. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
8d58e250b0
commit
8a0acf2c67
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue