Skip to content

Commit 9535e8a

Browse files
samyronbyroot
authored andcommitted
Add a fast path when copying a single unescape character to the output buffer.
1 parent b8e5be7 commit 9535e8a

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
@@ -769,8 +769,12 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c
769769
cursor.p = cursor.pe;
770770
continue;
771771
}
772-
MEMCPY(cursor.buffer, unescape, char, unescape_len);
773-
cursor.buffer += unescape_len;
772+
if (RB_LIKELY(unescape_len == 1)) {
773+
*cursor.buffer++ = *unescape;
774+
} else {
775+
MEMCPY(cursor.buffer, unescape, char, unescape_len);
776+
cursor.buffer += unescape_len;
777+
}
774778
cursor.p = ++cursor.pe;
775779
}
776780

0 commit comments

Comments
 (0)