3 ms·
The SWAR escaping algorithm [1] is very similar to the one I implemented in Folly JSON a few years ago [2]. The latter works on 8 byte words instead of 4 bytes,
by ot 1y ago
The SWAR escaping algorithm [1] is very similar to the one I implemented in Folly JSON a few years ago [2]. The latter works on 8 byte words instead of 4 bytes, and it also returns the position of the first byte that needs escaping, so that the fast path does not add noticeable overhead on escape-heavy strings.
[1] https://source.chromium.org/chromium/_/chromium/v8/v8/+/5cbc55a855df103fa257fb0db1cc72db72706488:src/json/json-stringifier.cc;dlc=c0b1106da565c4baecb23dc06272caefc50b6760 https://source.chromium.org/chromium/_/chromium/v8/v8/+/5cbc...
[2] https://github.com/facebook/folly/commit/2f0cabfb48b8a8df84f6453ef055e03ee1a34d51 https://github.com/facebook/folly/commit/2f0cabfb48b8a8df84f...
- hairtuq 1y agoIf you want to optimize it a little more, you can combine isLess(s, 0x20) and isChar('"') into isLess(s ^ (kOnes * 0x02), 0x21) (this works since '"' is 0x22).