Skip to content

Commit 864ef5b

Browse files
committed
Add a fast path when copying a single unescape character to the output buffer.
1 parent 56d79fc commit 864ef5b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/json/ext/parser/parser.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,12 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c
780780
cursor.p = cursor.pe;
781781
continue;
782782
}
783-
MEMCPY(cursor.buffer, unescape, char, unescape_len);
784-
cursor.buffer += unescape_len;
783+
if (RB_LIKELY(unescape_len == 1)) {
784+
*cursor.buffer++ = *unescape;
785+
} else {
786+
MEMCPY(cursor.buffer, unescape, char, unescape_len);
787+
cursor.buffer += unescape_len;
788+
}
785789
cursor.p = ++cursor.pe;
786790
}
787791

0 commit comments

Comments
 (0)