Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,22 @@ json_eat_comments(JSON_ParserState *state)
static inline void
json_eat_whitespace(JSON_ParserState *state)
{
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
// Heuristic: if we see a newline, there may be consecutive of spaces after it.
if (RB_UNLIKELY(state->cursor < state->end && *state->cursor == '\n')) {
state->cursor++;

while (state->cursor+sizeof(uint64_t) <= state->end) {
uint64_t chunk;
memcpy(&chunk, state->cursor, sizeof(uint64_t));
if (chunk != 0x2020202020202020) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do even better.

Unless I'm mistaken, we can get the exact number of consecutive spaces with:

__builtin_ctzll(bytes ^ 0x2020202020202020) / 8

break;
}
state->cursor += sizeof(uint64_t);
}
}
#endif

unsigned char cursor;
while (RB_UNLIKELY(whitespace[cursor = (unsigned char)peek(state)])) {
if (RB_UNLIKELY(cursor == '/')) {
Expand Down
Loading