20 #if defined(__SSE4_2__) 21 # define RAPIDJSON_SSE42 22 #elif defined(__SSE2__) 23 # define RAPIDJSON_SSE2 24 #elif defined(__ARM_NEON) 25 # define RAPIDJSON_NEON 28 #define RAPIDJSON_NAMESPACE rapidjson_simd 37 RAPIDJSON_DIAG_OFF(effc++)
43 #define SIMD_SUFFIX(name) name##_SSE2 44 #elif defined(RAPIDJSON_SSE42) 45 #define SIMD_SUFFIX(name) name##_SSE42 46 #elif defined(RAPIDJSON_NEON) 47 #define SIMD_SUFFIX(name) name##_NEON 49 #define SIMD_SUFFIX(name) name 52 template <
typename StreamType>
54 for (
size_t step = 1; step < 32; step++) {
56 for (
size_t i = 0; i < 1024; i++)
57 buffer[i] =
" \t\r\n"[i % 4];
58 for (
size_t i = 0; i < 1024; i += step)
68 EXPECT_EQ(i, s.Tell());
69 EXPECT_EQ(
'X', s.Take());
76 TestSkipWhitespace<StringStream>();
77 TestSkipWhitespace<InsituStringStream>();
81 for (
size_t step = 1; step < 32; step++) {
83 for (
size_t i = 0; i < 1024; i++)
84 buffer[i] =
" \t\r\n"[i % 4];
85 for (
size_t i = 0; i < 1024; i += step)
96 EXPECT_EQ(
'X', s.
Take());
103 bool String(
const char* str,
size_t length,
bool) {
104 memcpy(buffer, str, length + 1);
107 char buffer[1024 + 5 + 32];
110 template <
unsigned parseFlags,
typename StreamType>
112 char buffer[1024 + 5 + 32];
113 char backup[1024 + 5 + 32];
116 for (
size_t offset = 0; offset < 32; offset++) {
117 for (
size_t step = 0; step < 1024; step++) {
118 char*
json = buffer + offset;
121 for (
size_t i = 0; i < step; i++)
122 *p++ =
"ABCD"[i % 4];
127 strcpy(backup, json);
132 reader.
Parse<parseFlags>(s, h);
133 EXPECT_TRUE(memcmp(h.
buffer, backup + 1, step) == 0);
134 EXPECT_EQ(
'\\', h.
buffer[step]);
135 EXPECT_EQ(
'\0', h.
buffer[step + 1]);
140 for (
size_t offset = 0; offset < 32; offset++) {
141 for (
size_t step = 0; step < 1024; step++) {
142 char*
json = buffer + offset;
147 for (
size_t i = 0; i < step; i++)
148 *p++ =
"ABCD"[i % 4];
151 strcpy(backup, json);
156 reader.
Parse<parseFlags>(s, h);
157 EXPECT_TRUE(memcmp(h.
buffer + 1, backup + 3, step) == 0);
158 EXPECT_EQ(
'\\', h.
buffer[0]);
159 EXPECT_EQ(
'\0', h.
buffer[step + 1]);
165 TestScanCopyUnescapedString<kParseDefaultFlags, StringStream>();
166 TestScanCopyUnescapedString<kParseInsituFlag, InsituStringStream>();
170 char buffer[2048 + 1 + 32];
171 for (
size_t offset = 0; offset < 32; offset++) {
172 for (
size_t step = 0; step < 1024; step++) {
173 char*
s = buffer + offset;
175 for (
size_t i = 0; i < step; i++)
176 *p++ =
"ABCD"[i % 4];
177 char escape =
"\0\n\\\""[step % 4];
179 for (
size_t i = 0; i < step; i++)
180 *p++ =
"ABCD"[i % 4];
186 EXPECT_EQ(
'\"', *q++);
187 for (
size_t i = 0; i < step; i++)
188 EXPECT_EQ(
"ABCD"[i % 4], *q++);
189 if (escape ==
'\0') {
190 EXPECT_EQ(
'\\', *q++);
191 EXPECT_EQ(
'u', *q++);
192 EXPECT_EQ(
'0', *q++);
193 EXPECT_EQ(
'0', *q++);
194 EXPECT_EQ(
'0', *q++);
195 EXPECT_EQ(
'0', *q++);
197 else if (escape ==
'\n') {
198 EXPECT_EQ(
'\\', *q++);
199 EXPECT_EQ(
'n', *q++);
201 else if (escape ==
'\\') {
202 EXPECT_EQ(
'\\', *q++);
203 EXPECT_EQ(
'\\', *q++);
205 else if (escape ==
'\"') {
206 EXPECT_EQ(
'\\', *q++);
207 EXPECT_EQ(
'\"', *q++);
209 for (
size_t i = 0; i < step; i++)
210 EXPECT_EQ(
"ABCD"[i % 4], *q++);
211 EXPECT_EQ(
'\"', *q++);
212 EXPECT_EQ(
'\0', *q++);
TEST(SIMD, SIMD_SUFFIX(SkipWhitespace))
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Represents an in-memory input byte stream.
void TestScanCopyUnescapedString()
bool String(const char *str, size_t length, bool)
Default implementation of Handler.
const Ch * GetString() const
bool String(const Ch *str, SizeType length, bool copy=false)
void TestSkipWhitespace()
#define SIMD_SUFFIX(name)
void SkipWhitespace(InputStream &is)
Skip the JSON white spaces in a stream.