diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-06-24 15:34:36 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-06-24 15:34:36 +0200 |
commit | f6e7e761f4a42df9b975cd8c3b1e551d845a6d46 (patch) | |
tree | 25d1b23d5ddf6f1df02a651291e72b4a2a8442c8 /src/lexer.c | |
parent | 0696c3d2ab59166e7519c2a9de273f7f498b1eaa (diff) |
Utilize SSE4.1 to skip comments at 2x speed
Diffstat (limited to 'src/lexer.c')
-rw-r--r-- | src/lexer.c | 30 |
1 files changed, 2 insertions, 28 deletions
diff --git a/src/lexer.c b/src/lexer.c index ed2414a..0ed057d 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -32,7 +32,7 @@ static void lexemesresz(lexemes_t *toks) /* Advance PTR (which points to the start of a comment) to the end of the comment, or END. Returns true if the comment was well-formed and false if the comment was unterminated. Handles nested comments. */ -static bool skip_comment(const uchar **ptr, const uchar *end) +bool skpcmnt(const uchar **ptr, const uchar *end) __attribute__((nonnull)); static const bool is_numeric_lookup[UCHAR_MAX + 1] = { @@ -88,7 +88,7 @@ lexstring(const uchar *code, size_t codesz) /* Single- or double-byte literals */ case '/': if (code < end && code[0] == '*') { - if (!skip_comment(&code, end)) + if (!skpcmnt(&code, end)) err("Unterminated comment at byte %td", code - start); continue; } @@ -172,32 +172,6 @@ fallback: return data; } -bool -skip_comment(const uchar **ptr, const uchar *end) -{ - int nst = 1; - const uchar *p = *ptr; - - for (p++; likely(p < end); p++) { - if (p + 1 < end) { - if (p[0] == '*' && p[1] == '/') { - p++; - if (--nst == 0) - goto out; - } else if (p[0] == '/' && p[1] == '*') { - p++; - nst++; - } - } - } - - return false; - -out: - *ptr = ++p; - return true; -} - lexemes_t mklexemes(void) { |