Skip to content

Commit

Permalink
Yoink
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB authored Jul 3, 2024
1 parent 8d85d0d commit 124cacb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/WebSocketProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ T cond_byte_swap(T value) {
// https://www.cl.cam.ac.uk/~mgk25/ucs/utf8_check.c
// Optimized for predominantly 7-bit content by Alex Hultman, 2016
// Licensed as Zlib, like the rest of this project
// This runs about 40% faster than simdutf with g++ -mavx
static bool isValidUtf8(unsigned char *s, size_t length)
{
for (unsigned char *e = s + length; s != e; ) {
if (s + 4 <= e) {
uint32_t tmp;
memcpy(&tmp, s, 4);
if ((tmp & 0x80808080) == 0) {
s += 4;
if (s + 16 <= e) {
uint64_t tmp[2];
memcpy(&tmp, s, 16);
if (((tmp[0] & 0x8080808080808080) | (tmp[1] & 0x8080808080808080)) == 0) {
s += 16;
continue;
}
}
Expand Down

0 comments on commit 124cacb

Please sign in to comment.