Skip to content

Commit da4fd67

Browse files
author
Alejandro Martinez
committed
Fixed bug on space hexadecimal encoding
1 parent 430e8d4 commit da4fd67

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

include/rapidjson/reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ class GenericReader {
990990
// The rest of string using SIMD
991991
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
992992
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
993-
static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
993+
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
994994
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
995995
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
996996
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
@@ -999,7 +999,7 @@ class GenericReader {
999999
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
10001000
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
10011001
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1002-
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x19) == 0x19
1002+
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
10031003
const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
10041004
unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
10051005
if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
@@ -1053,7 +1053,7 @@ class GenericReader {
10531053
// The rest of string using SIMD
10541054
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
10551055
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
1056-
static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
1056+
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
10571057
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
10581058
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
10591059
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
@@ -1062,7 +1062,7 @@ class GenericReader {
10621062
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
10631063
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
10641064
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1065-
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x19) == 0x19
1065+
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
10661066
const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
10671067
unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
10681068
if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
@@ -1101,7 +1101,7 @@ class GenericReader {
11011101
// The rest of string using SIMD
11021102
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
11031103
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
1104-
static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
1104+
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
11051105
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
11061106
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
11071107
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
@@ -1110,7 +1110,7 @@ class GenericReader {
11101110
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
11111111
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
11121112
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1113-
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x19) == 0x19
1113+
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
11141114
const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
11151115
unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
11161116
if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped

include/rapidjson/writer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
585585
// The rest of string using SIMD
586586
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
587587
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
588-
static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
588+
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
589589
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
590590
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
591591
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
@@ -594,7 +594,7 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
594594
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
595595
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
596596
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
597-
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x19) == 0x19
597+
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
598598
const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
599599
unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
600600
if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped

0 commit comments

Comments
 (0)