Skip to content

Commit 72c6c01

Browse files
code cleanup
1 parent dbd72b1 commit 72c6c01

1 file changed

Lines changed: 3 additions & 82 deletions

File tree

src/json.c

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Created:
66
* April 12, 1961 at 09:07:34 PM GMT+3
77
* Modified:
8-
* February 16, 2026 at 9:09:56 PM GMT+3
8+
* February 16, 2026 at 9:38:04 PM GMT+3
99
*
1010
*/
1111
/*
@@ -223,9 +223,6 @@ static INLINE bool INLINE_ATTRIBUTE parse_string(const char **s, const char *end
223223
while (true) {
224224
const size_t len = end - p;
225225
size_t span = 0;
226-
const char *s_chk = p - span;
227-
size_t len_chk = span;
228-
size_t j = 0;
229226
#if defined(__AVX2__)
230227
const size_t offset_2 = 32;
231228
const size_t offset_4 = 64;
@@ -267,30 +264,6 @@ static INLINE bool INLINE_ATTRIBUTE parse_string(const char **s, const char *end
267264
goto found;
268265
}
269266
}
270-
#if STRING_VALIDATION
271-
const __m256i limit2 = _mm256_set1_epi8(MIN_PRINTABLE_ASCII);
272-
const __m256i high_bit2 = _mm256_set1_epi8(MAX_PRINTABLE_ASCII);
273-
const __m256i limit_shifted2 = _mm256_xor_si256(limit2, high_bit2);
274-
for (; j + offset_4 <= len_chk; j += offset_4) {
275-
__m256i chunk1 = _mm256_loadu_si256((const __m256i *)(s_chk + j));
276-
__m256i chunk2 = _mm256_loadu_si256((const __m256i *)(s_chk + j + offset_2));
277-
__m256i chunk1_shifted = _mm256_xor_si256(chunk1, high_bit2);
278-
__m256i chunk2_shifted = _mm256_xor_si256(chunk2, high_bit2);
279-
__m256i result_mask1 = _mm256_cmpgt_epi8(limit_shifted2, chunk1_shifted);
280-
__m256i result_mask2 = _mm256_cmpgt_epi8(limit_shifted2, chunk2_shifted);
281-
if (_mm256_movemask_epi8(result_mask1) != 0 || _mm256_movemask_epi8(result_mask2) != 0) {
282-
return false;
283-
}
284-
}
285-
for (; j + offset_2 <= len_chk; j += offset_2) {
286-
__m256i chunk = _mm256_loadu_si256((const __m256i *)(s_chk + j));
287-
__m256i chunk_shifted = _mm256_xor_si256(chunk, high_bit2);
288-
__m256i result_mask = _mm256_cmpgt_epi8(limit_shifted2, chunk_shifted);
289-
if (_mm256_movemask_epi8(result_mask) != 0) {
290-
return false;
291-
}
292-
}
293-
#endif
294267
span = len;
295268
#elif defined(__SSE2__)
296269
const size_t offset_1 = 16;
@@ -349,37 +322,6 @@ static INLINE bool INLINE_ATTRIBUTE parse_string(const char **s, const char *end
349322
goto found;
350323
}
351324
}
352-
#if STRING_VALIDATION
353-
const __m128i limit2 = _mm_set1_epi8(MIN_PRINTABLE_ASCII);
354-
const __m128i high_bit2 = _mm_set1_epi8(MAX_PRINTABLE_ASCII);
355-
const __m128i limit_shifted2 = _mm_xor_si128(limit2, high_bit2);
356-
for (; j + offset_4 <= len_chk; j += offset_4) {
357-
__m128i chunk1 = _mm_loadu_si128((const __m128i *)(s_chk + j));
358-
__m128i chunk2 = _mm_loadu_si128((const __m128i *)(s_chk + j + offset_1));
359-
__m128i chunk3 = _mm_loadu_si128((const __m128i *)(s_chk + j + offset_2));
360-
__m128i chunk4 = _mm_loadu_si128((const __m128i *)(s_chk + j + offset_3));
361-
__m128i chunk1_shifted = _mm_xor_si128(chunk1, high_bit2);
362-
__m128i chunk2_shifted = _mm_xor_si128(chunk2, high_bit2);
363-
__m128i chunk3_shifted = _mm_xor_si128(chunk3, high_bit2);
364-
__m128i chunk4_shifted = _mm_xor_si128(chunk4, high_bit2);
365-
__m128i result_mask1 = _mm_cmplt_epi8(chunk1_shifted, limit_shifted2);
366-
__m128i result_mask2 = _mm_cmplt_epi8(chunk2_shifted, limit_shifted2);
367-
__m128i result_mask3 = _mm_cmplt_epi8(chunk3_shifted, limit_shifted2);
368-
__m128i result_mask4 = _mm_cmplt_epi8(chunk4_shifted, limit_shifted2);
369-
if (_mm_movemask_epi8(result_mask1) != 0 || _mm_movemask_epi8(result_mask2) != 0 ||
370-
_mm_movemask_epi8(result_mask3) != 0 || _mm_movemask_epi8(result_mask4) != 0) {
371-
return false;
372-
}
373-
}
374-
for (; j + offset_1 <= len_chk; j += offset_1) {
375-
__m128i chunk = _mm_loadu_si128((const __m128i *)(s_chk + j));
376-
__m128i chunk_shifted = _mm_xor_si128(chunk, high_bit2);
377-
__m128i result_mask = _mm_cmplt_epi8(chunk_shifted, limit_shifted2);
378-
if (_mm_movemask_epi8(result_mask) != 0) {
379-
return false;
380-
}
381-
}
382-
#endif
383325
span = len;
384326
#else
385327
/* non-SSE2 fallback: simple byte scan */
@@ -393,30 +335,13 @@ static INLINE bool INLINE_ATTRIBUTE parse_string(const char **s, const char *end
393335
span = len;
394336
#endif
395337

396-
for (; j < len_chk; j++) {
397-
if ((unsigned char)s_chk[j] < MIN_PRINTABLE_ASCII) {
398-
return false;
399-
}
400-
}
401-
402-
/* scalar tail */
403-
for (; i < len; i++) {
404-
if ((unsigned char)p[i] < MIN_PRINTABLE_ASCII || (unsigned char)p[i] >= MAX_PRINTABLE_ASCII) {
405-
return false;
406-
}
407-
if (p[i] == '"' || p[i] == '\\') {
408-
span = i;
409-
goto found;
410-
}
411-
}
412-
413-
return false;
414338
found:
415339
p += span;
416340
if (p == end)
417341
return false;
418342
if (*p == '"') {
419343
/* Inline SIMD validation for the parsed string span */
344+
#if STRING_VALIDATION
420345
const char *chk = v->u.string.ptr;
421346
size_t chk_len = (size_t)(p - chk);
422347
size_t ii = 0;
@@ -474,11 +399,7 @@ static INLINE bool INLINE_ATTRIBUTE parse_string(const char **s, const char *end
474399
if (_mm_movemask_epi8(rm) != 0)
475400
return false;
476401
}
477-
for (; ii < chk_len; ii++) {
478-
if ((unsigned char)chk[ii] < MIN_PRINTABLE_ASCII)
479-
return false;
480-
}
481-
#else
402+
#endif
482403
for (; ii < chk_len; ii++) {
483404
if ((unsigned char)chk[ii] < MIN_PRINTABLE_ASCII)
484405
return false;

0 commit comments

Comments
 (0)