Skip to content

Commit 65f0af8

Browse files
authored
add enable simd utf8 macro (#1870)
* add enable simd utf8 macro * change macro to UWS_USE_SIMDUTF
1 parent 000d9fe commit 65f0af8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/WebSocketProtocol.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <cstdlib>
2626
#include <string_view>
2727

28+
#ifdef UWS_USE_SIMDUTF
29+
#include <simdutf.h>
30+
#endif
31+
2832
namespace uWS {
2933

3034
/* We should not overcomplicate these */
@@ -113,6 +117,14 @@ T cond_byte_swap(T value) {
113117
return value;
114118
}
115119

120+
#ifdef UWS_USE_SIMDUTF
121+
122+
static bool isValidUtf8(unsigned char *s, size_t length)
123+
{
124+
return simdutf::validate_utf8((const char *)s, length);
125+
}
126+
127+
#else
116128
// Based on utf8_check.c by Markus Kuhn, 2005
117129
// https://www.cl.cam.ac.uk/~mgk25/ucs/utf8_check.c
118130
// Optimized for predominantly 7-bit content by Alex Hultman, 2016
@@ -160,6 +172,8 @@ static bool isValidUtf8(unsigned char *s, size_t length)
160172
return true;
161173
}
162174

175+
#endif
176+
163177
struct CloseFrame {
164178
uint16_t code;
165179
char *message;

0 commit comments

Comments
 (0)