Skip to content

Commit a14431c

Browse files
committed
Avoid redundant whitespace scanning in magic comment lexing
1 parent 83f54c2 commit a14431c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/prism.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7587,11 +7587,17 @@ parser_lex_magic_comment(pm_parser_t *parser, bool semantic_token_seen) {
75877587
if (pm_memchr(start, ':', (size_t) (end - start), parser->encoding_changed, parser->encoding) == NULL) {
75887588
return false;
75897589
}
7590+
7591+
// Advance start past leading whitespace so the main loop begins
7592+
// directly at the key, avoiding a redundant whitespace scan.
7593+
start += pm_strspn_whitespace(start, end - start);
75907594
}
75917595

75927596
cursor = start;
75937597
while (cursor < end) {
7594-
while (cursor < end && (pm_char_is_magic_comment_key_delimiter(*cursor) || pm_char_is_whitespace(*cursor))) cursor++;
7598+
if (indicator) {
7599+
cursor += pm_strspn_whitespace(cursor, end - cursor);
7600+
}
75957601

75967602
const uint8_t *key_start = cursor;
75977603
while (cursor < end && (!pm_char_is_magic_comment_key_delimiter(*cursor) && !pm_char_is_whitespace(*cursor))) cursor++;

0 commit comments

Comments
 (0)