Skip to content

Commit c1ad25e

Browse files
committed
Scan forward through inline whitespace to avoid writing to parser->current.end continuously
1 parent e0708c4 commit c1ad25e

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/prism.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9658,17 +9658,24 @@ parser_lex(pm_parser_t *parser) {
96589658
bool space_seen = false;
96599659

96609660
// First, we're going to skip past any whitespace at the front of the next
9661-
// token.
9661+
// token. Skip runs of inline whitespace in bulk to avoid per-character
9662+
// stores back to parser->current.end.
96629663
bool chomping = true;
96639664
while (parser->current.end < parser->end && chomping) {
9664-
switch (*parser->current.end) {
9665-
case ' ':
9666-
case '\t':
9667-
case '\f':
9668-
case '\v':
9669-
parser->current.end++;
9665+
{
9666+
static const uint8_t inline_whitespace[256] = {
9667+
[' '] = 1, ['\t'] = 1, ['\f'] = 1, ['\v'] = 1
9668+
};
9669+
const uint8_t *scan = parser->current.end;
9670+
while (scan < parser->end && inline_whitespace[*scan]) scan++;
9671+
if (scan > parser->current.end) {
9672+
parser->current.end = scan;
96709673
space_seen = true;
9671-
break;
9674+
continue;
9675+
}
9676+
}
9677+
9678+
switch (*parser->current.end) {
96729679
case '\r':
96739680
if (match_eol_offset(parser, 1)) {
96749681
chomping = false;

0 commit comments

Comments
 (0)