Skip to content

Commit 3efa780

Browse files
committed
heuristic to skip chunks of leading whitespace when parsing
1 parent 8f5c7f9 commit 3efa780

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ext/json/ext/parser/parser.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,21 @@ json_eat_comments(JSON_ParserState *state)
591591
static inline void
592592
json_eat_whitespace(JSON_ParserState *state)
593593
{
594+
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
595+
if (RB_UNLIKELY(state->cursor < state->end && *state->cursor == '\n')) {
596+
state->cursor++;
597+
598+
while (state->cursor+sizeof(uint64_t) <= state->end) {
599+
uint64_t chunk;
600+
memcpy(&chunk, state->cursor, sizeof(uint64_t));
601+
if (chunk != 0x2020202020202020) {
602+
break;
603+
}
604+
state->cursor += sizeof(uint64_t);
605+
}
606+
}
607+
#endif
608+
594609
while (state->cursor < state->end && RB_UNLIKELY(whitespace[(unsigned char)*state->cursor])) {
595610
if (RB_LIKELY(*state->cursor != '/')) {
596611
state->cursor++;

0 commit comments

Comments
 (0)