mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 07:09:48 -06:00
update the rapidjson used by discord-rpc to current master dfbe1db9da455552f7a9ad5d2aea17dd9d832ac1
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include "allocators.h"
|
||||
#include "stream.h"
|
||||
#include "encodedstream.h"
|
||||
#include "internal/clzll.h"
|
||||
#include "internal/meta.h"
|
||||
#include "internal/stack.h"
|
||||
#include "internal/strtod.h"
|
||||
@ -33,12 +34,8 @@
|
||||
#include <nmmintrin.h>
|
||||
#elif defined(RAPIDJSON_SSE2)
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
|
||||
RAPIDJSON_DIAG_OFF(4702) // unreachable code
|
||||
#elif defined(RAPIDJSON_NEON)
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
@ -46,6 +43,10 @@ RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(old-style-cast)
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
RAPIDJSON_DIAG_OFF(switch-enum)
|
||||
#elif defined(_MSC_VER)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
|
||||
RAPIDJSON_DIAG_OFF(4702) // unreachable code
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
@ -299,16 +300,9 @@ inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
|
||||
for (;; p += 16) {
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const int r = _mm_cvtsi128_si32(_mm_cmpistrm(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK | _SIDD_NEGATIVE_POLARITY));
|
||||
if (r != 0) { // some of characters is non-whitespace
|
||||
#ifdef _MSC_VER // Find the index of first non-whitespace
|
||||
unsigned long offset;
|
||||
_BitScanForward(&offset, r);
|
||||
return p + offset;
|
||||
#else
|
||||
return p + __builtin_ffs(r) - 1;
|
||||
#endif
|
||||
}
|
||||
const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
|
||||
if (r != 16) // some of characters is non-whitespace
|
||||
return p + r;
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,16 +319,9 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
|
||||
for (; p <= end - 16; p += 16) {
|
||||
const __m128i s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const int r = _mm_cvtsi128_si32(_mm_cmpistrm(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK | _SIDD_NEGATIVE_POLARITY));
|
||||
if (r != 0) { // some of characters is non-whitespace
|
||||
#ifdef _MSC_VER // Find the index of first non-whitespace
|
||||
unsigned long offset;
|
||||
_BitScanForward(&offset, r);
|
||||
return p + offset;
|
||||
#else
|
||||
return p + __builtin_ffs(r) - 1;
|
||||
#endif
|
||||
}
|
||||
const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
|
||||
if (r != 16) // some of characters is non-whitespace
|
||||
return p + r;
|
||||
}
|
||||
|
||||
return SkipWhitespace(p, end);
|
||||
@ -425,7 +412,92 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
return SkipWhitespace(p, end);
|
||||
}
|
||||
|
||||
#endif // RAPIDJSON_SSE2
|
||||
#elif defined(RAPIDJSON_NEON)
|
||||
|
||||
//! Skip whitespace with ARM Neon instructions, testing 16 8-byte characters at once.
|
||||
inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
// Fast return for single non-whitespace
|
||||
if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
|
||||
++p;
|
||||
else
|
||||
return p;
|
||||
|
||||
// 16-byte align to the next boundary
|
||||
const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
|
||||
while (p != nextAligned)
|
||||
if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
|
||||
++p;
|
||||
else
|
||||
return p;
|
||||
|
||||
const uint8x16_t w0 = vmovq_n_u8(' ');
|
||||
const uint8x16_t w1 = vmovq_n_u8('\n');
|
||||
const uint8x16_t w2 = vmovq_n_u8('\r');
|
||||
const uint8x16_t w3 = vmovq_n_u8('\t');
|
||||
|
||||
for (;; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
|
||||
uint8x16_t x = vceqq_u8(s, w0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, w1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, w2));
|
||||
x = vorrq_u8(x, vceqq_u8(s, w3));
|
||||
|
||||
x = vmvnq_u8(x); // Negate
|
||||
x = vrev64q_u8(x); // Rev in 64
|
||||
uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract
|
||||
uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract
|
||||
|
||||
if (low == 0) {
|
||||
if (high != 0) {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(high);
|
||||
return p + 8 + (lz >> 3);
|
||||
}
|
||||
} else {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(low);
|
||||
return p + (lz >> 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
// Fast return for single non-whitespace
|
||||
if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'))
|
||||
++p;
|
||||
else
|
||||
return p;
|
||||
|
||||
const uint8x16_t w0 = vmovq_n_u8(' ');
|
||||
const uint8x16_t w1 = vmovq_n_u8('\n');
|
||||
const uint8x16_t w2 = vmovq_n_u8('\r');
|
||||
const uint8x16_t w3 = vmovq_n_u8('\t');
|
||||
|
||||
for (; p <= end - 16; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
|
||||
uint8x16_t x = vceqq_u8(s, w0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, w1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, w2));
|
||||
x = vorrq_u8(x, vceqq_u8(s, w3));
|
||||
|
||||
x = vmvnq_u8(x); // Negate
|
||||
x = vrev64q_u8(x); // Rev in 64
|
||||
uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract
|
||||
uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract
|
||||
|
||||
if (low == 0) {
|
||||
if (high != 0) {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(high);
|
||||
return p + 8 + (lz >> 3);
|
||||
}
|
||||
} else {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(low);
|
||||
return p + (lz >> 3);
|
||||
}
|
||||
}
|
||||
|
||||
return SkipWhitespace(p, end);
|
||||
}
|
||||
|
||||
#endif // RAPIDJSON_NEON
|
||||
|
||||
#ifdef RAPIDJSON_SIMD
|
||||
//! Template function specialization for InsituStringStream
|
||||
@ -471,7 +543,8 @@ public:
|
||||
/*! \param stackAllocator Optional allocator for allocating stack memory. (Only use for non-destructive parsing)
|
||||
\param stackCapacity stack capacity in bytes for storing a single decoded string. (Only use for non-destructive parsing)
|
||||
*/
|
||||
GenericReader(StackAllocator* stackAllocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(stackAllocator, stackCapacity), parseResult_() {}
|
||||
GenericReader(StackAllocator* stackAllocator = 0, size_t stackCapacity = kDefaultStackCapacity) :
|
||||
stack_(stackAllocator, stackCapacity), parseResult_(), state_(IterativeParsingStartState) {}
|
||||
|
||||
//! Parse JSON text.
|
||||
/*! \tparam parseFlags Combination of \ref ParseFlag.
|
||||
@ -527,7 +600,84 @@ public:
|
||||
return Parse<kParseDefaultFlags>(is, handler);
|
||||
}
|
||||
|
||||
//! Whether a parse error has occured in the last parsing.
|
||||
//! Initialize JSON text token-by-token parsing
|
||||
/*!
|
||||
*/
|
||||
void IterativeParseInit() {
|
||||
parseResult_.Clear();
|
||||
state_ = IterativeParsingStartState;
|
||||
}
|
||||
|
||||
//! Parse one token from JSON text
|
||||
/*! \tparam InputStream Type of input stream, implementing Stream concept
|
||||
\tparam Handler Type of handler, implementing Handler concept.
|
||||
\param is Input stream to be parsed.
|
||||
\param handler The handler to receive events.
|
||||
\return Whether the parsing is successful.
|
||||
*/
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
bool IterativeParseNext(InputStream& is, Handler& handler) {
|
||||
while (RAPIDJSON_LIKELY(is.Peek() != '\0')) {
|
||||
SkipWhitespaceAndComments<parseFlags>(is);
|
||||
|
||||
Token t = Tokenize(is.Peek());
|
||||
IterativeParsingState n = Predict(state_, t);
|
||||
IterativeParsingState d = Transit<parseFlags>(state_, t, n, is, handler);
|
||||
|
||||
// If we've finished or hit an error...
|
||||
if (RAPIDJSON_UNLIKELY(IsIterativeParsingCompleteState(d))) {
|
||||
// Report errors.
|
||||
if (d == IterativeParsingErrorState) {
|
||||
HandleError(state_, is);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Transition to the finish state.
|
||||
RAPIDJSON_ASSERT(d == IterativeParsingFinishState);
|
||||
state_ = d;
|
||||
|
||||
// If StopWhenDone is not set...
|
||||
if (!(parseFlags & kParseStopWhenDoneFlag)) {
|
||||
// ... and extra non-whitespace data is found...
|
||||
SkipWhitespaceAndComments<parseFlags>(is);
|
||||
if (is.Peek() != '\0') {
|
||||
// ... this is considered an error.
|
||||
HandleError(state_, is);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Success! We are done!
|
||||
return true;
|
||||
}
|
||||
|
||||
// Transition to the new state.
|
||||
state_ = d;
|
||||
|
||||
// If we parsed anything other than a delimiter, we invoked the handler, so we can return true now.
|
||||
if (!IsIterativeParsingDelimiterState(n))
|
||||
return true;
|
||||
}
|
||||
|
||||
// We reached the end of file.
|
||||
stack_.Clear();
|
||||
|
||||
if (state_ != IterativeParsingFinishState) {
|
||||
HandleError(state_, is);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Check if token-by-token parsing JSON text is complete
|
||||
/*! \return Whether the JSON has been fully decoded.
|
||||
*/
|
||||
RAPIDJSON_FORCEINLINE bool IterativeParseComplete() const {
|
||||
return IsIterativeParsingCompleteState(state_);
|
||||
}
|
||||
|
||||
//! Whether a parse error has occurred in the last parsing.
|
||||
bool HasParseError() const { return parseResult_.IsError(); }
|
||||
|
||||
//! Get the \ref ParseErrorCode of last parsing.
|
||||
@ -575,7 +725,7 @@ private:
|
||||
}
|
||||
}
|
||||
else if (RAPIDJSON_LIKELY(Consume(is, '/')))
|
||||
while (is.Peek() != '\0' && is.Take() != '\n');
|
||||
while (is.Peek() != '\0' && is.Take() != '\n') {}
|
||||
else
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorUnspecificSyntaxError, is.Tell());
|
||||
|
||||
@ -750,7 +900,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Helper function to parse four hexidecimal digits in \uXXXX in ParseString().
|
||||
// Helper function to parse four hexadecimal digits in \uXXXX in ParseString().
|
||||
template<typename InputStream>
|
||||
unsigned ParseHex4(InputStream& is, size_t escapeOffset) {
|
||||
unsigned codepoint = 0;
|
||||
@ -857,7 +1007,7 @@ private:
|
||||
|
||||
Ch c = is.Peek();
|
||||
if (RAPIDJSON_UNLIKELY(c == '\\')) { // Escape
|
||||
size_t escapeOffset = is.Tell(); // For invalid escaping, report the inital '\\' as error offset
|
||||
size_t escapeOffset = is.Tell(); // For invalid escaping, report the initial '\\' as error offset
|
||||
is.Take();
|
||||
Ch e = is.Peek();
|
||||
if ((sizeof(Ch) == 1 || unsigned(e) < 256) && RAPIDJSON_LIKELY(escape[static_cast<unsigned char>(e)])) {
|
||||
@ -892,7 +1042,7 @@ private:
|
||||
if (c == '\0')
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorStringMissQuotationMark, is.Tell());
|
||||
else
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorStringEscapeInvalid, is.Tell());
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorStringInvalidEncoding, is.Tell());
|
||||
}
|
||||
else {
|
||||
size_t offset = is.Tell();
|
||||
@ -927,7 +1077,7 @@ private:
|
||||
// The rest of string using SIMD
|
||||
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
|
||||
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
|
||||
static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
|
||||
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
|
||||
@ -936,7 +1086,7 @@ private:
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
|
||||
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x19) == 0x19
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
|
||||
const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
|
||||
unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
|
||||
if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
|
||||
@ -948,11 +1098,13 @@ private:
|
||||
#else
|
||||
length = static_cast<SizeType>(__builtin_ffs(r) - 1);
|
||||
#endif
|
||||
char* q = reinterpret_cast<char*>(os.Push(length));
|
||||
for (size_t i = 0; i < length; i++)
|
||||
q[i] = p[i];
|
||||
if (length != 0) {
|
||||
char* q = reinterpret_cast<char*>(os.Push(length));
|
||||
for (size_t i = 0; i < length; i++)
|
||||
q[i] = p[i];
|
||||
|
||||
p += length;
|
||||
p += length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
_mm_storeu_si128(reinterpret_cast<__m128i *>(os.Push(16)), s);
|
||||
@ -988,7 +1140,7 @@ private:
|
||||
// The rest of string using SIMD
|
||||
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
|
||||
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
|
||||
static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
|
||||
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
|
||||
@ -997,7 +1149,7 @@ private:
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
|
||||
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x19) == 0x19
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
|
||||
const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
|
||||
unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
|
||||
if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
|
||||
@ -1036,7 +1188,7 @@ private:
|
||||
// The rest of string using SIMD
|
||||
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
|
||||
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
|
||||
static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
|
||||
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
|
||||
@ -1045,7 +1197,7 @@ private:
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
|
||||
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x19) == 0x19
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
|
||||
const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
|
||||
unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
|
||||
if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
|
||||
@ -1064,7 +1216,180 @@ private:
|
||||
|
||||
is.src_ = is.dst_ = p;
|
||||
}
|
||||
#endif
|
||||
#elif defined(RAPIDJSON_NEON)
|
||||
// StringStream -> StackStream<char>
|
||||
static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(StringStream& is, StackStream<char>& os) {
|
||||
const char* p = is.src_;
|
||||
|
||||
// Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
|
||||
const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
|
||||
while (p != nextAligned)
|
||||
if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
|
||||
is.src_ = p;
|
||||
return;
|
||||
}
|
||||
else
|
||||
os.Put(*p++);
|
||||
|
||||
// The rest of string using SIMD
|
||||
const uint8x16_t s0 = vmovq_n_u8('"');
|
||||
const uint8x16_t s1 = vmovq_n_u8('\\');
|
||||
const uint8x16_t s2 = vmovq_n_u8('\b');
|
||||
const uint8x16_t s3 = vmovq_n_u8(32);
|
||||
|
||||
for (;; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
|
||||
uint8x16_t x = vceqq_u8(s, s0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, s1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, s2));
|
||||
x = vorrq_u8(x, vcltq_u8(s, s3));
|
||||
|
||||
x = vrev64q_u8(x); // Rev in 64
|
||||
uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract
|
||||
uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract
|
||||
|
||||
SizeType length = 0;
|
||||
bool escaped = false;
|
||||
if (low == 0) {
|
||||
if (high != 0) {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(high);
|
||||
length = 8 + (lz >> 3);
|
||||
escaped = true;
|
||||
}
|
||||
} else {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(low);
|
||||
length = lz >> 3;
|
||||
escaped = true;
|
||||
}
|
||||
if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped
|
||||
if (length != 0) {
|
||||
char* q = reinterpret_cast<char*>(os.Push(length));
|
||||
for (size_t i = 0; i < length; i++)
|
||||
q[i] = p[i];
|
||||
|
||||
p += length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
vst1q_u8(reinterpret_cast<uint8_t *>(os.Push(16)), s);
|
||||
}
|
||||
|
||||
is.src_ = p;
|
||||
}
|
||||
|
||||
// InsituStringStream -> InsituStringStream
|
||||
static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InsituStringStream& is, InsituStringStream& os) {
|
||||
RAPIDJSON_ASSERT(&is == &os);
|
||||
(void)os;
|
||||
|
||||
if (is.src_ == is.dst_) {
|
||||
SkipUnescapedString(is);
|
||||
return;
|
||||
}
|
||||
|
||||
char* p = is.src_;
|
||||
char *q = is.dst_;
|
||||
|
||||
// Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
|
||||
const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
|
||||
while (p != nextAligned)
|
||||
if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
|
||||
is.src_ = p;
|
||||
is.dst_ = q;
|
||||
return;
|
||||
}
|
||||
else
|
||||
*q++ = *p++;
|
||||
|
||||
// The rest of string using SIMD
|
||||
const uint8x16_t s0 = vmovq_n_u8('"');
|
||||
const uint8x16_t s1 = vmovq_n_u8('\\');
|
||||
const uint8x16_t s2 = vmovq_n_u8('\b');
|
||||
const uint8x16_t s3 = vmovq_n_u8(32);
|
||||
|
||||
for (;; p += 16, q += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
|
||||
uint8x16_t x = vceqq_u8(s, s0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, s1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, s2));
|
||||
x = vorrq_u8(x, vcltq_u8(s, s3));
|
||||
|
||||
x = vrev64q_u8(x); // Rev in 64
|
||||
uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract
|
||||
uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract
|
||||
|
||||
SizeType length = 0;
|
||||
bool escaped = false;
|
||||
if (low == 0) {
|
||||
if (high != 0) {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(high);
|
||||
length = 8 + (lz >> 3);
|
||||
escaped = true;
|
||||
}
|
||||
} else {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(low);
|
||||
length = lz >> 3;
|
||||
escaped = true;
|
||||
}
|
||||
if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped
|
||||
for (const char* pend = p + length; p != pend; ) {
|
||||
*q++ = *p++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
vst1q_u8(reinterpret_cast<uint8_t *>(q), s);
|
||||
}
|
||||
|
||||
is.src_ = p;
|
||||
is.dst_ = q;
|
||||
}
|
||||
|
||||
// When read/write pointers are the same for insitu stream, just skip unescaped characters
|
||||
static RAPIDJSON_FORCEINLINE void SkipUnescapedString(InsituStringStream& is) {
|
||||
RAPIDJSON_ASSERT(is.src_ == is.dst_);
|
||||
char* p = is.src_;
|
||||
|
||||
// Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
|
||||
const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
|
||||
for (; p != nextAligned; p++)
|
||||
if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
|
||||
is.src_ = is.dst_ = p;
|
||||
return;
|
||||
}
|
||||
|
||||
// The rest of string using SIMD
|
||||
const uint8x16_t s0 = vmovq_n_u8('"');
|
||||
const uint8x16_t s1 = vmovq_n_u8('\\');
|
||||
const uint8x16_t s2 = vmovq_n_u8('\b');
|
||||
const uint8x16_t s3 = vmovq_n_u8(32);
|
||||
|
||||
for (;; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
|
||||
uint8x16_t x = vceqq_u8(s, s0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, s1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, s2));
|
||||
x = vorrq_u8(x, vcltq_u8(s, s3));
|
||||
|
||||
x = vrev64q_u8(x); // Rev in 64
|
||||
uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract
|
||||
uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract
|
||||
|
||||
if (low == 0) {
|
||||
if (high != 0) {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(high);
|
||||
p += 8 + (lz >> 3);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
uint32_t lz = RAPIDJSON_CLZLL(low);
|
||||
p += lz >> 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
is.src_ = is.dst_ = p;
|
||||
}
|
||||
#endif // RAPIDJSON_NEON
|
||||
|
||||
template<typename InputStream, bool backup, bool pushOnTake>
|
||||
class NumberStream;
|
||||
@ -1075,12 +1400,11 @@ private:
|
||||
typedef typename InputStream::Ch Ch;
|
||||
|
||||
NumberStream(GenericReader& reader, InputStream& s) : is(s) { (void)reader; }
|
||||
~NumberStream() {}
|
||||
|
||||
RAPIDJSON_FORCEINLINE Ch Peek() const { return is.Peek(); }
|
||||
RAPIDJSON_FORCEINLINE Ch TakePush() { return is.Take(); }
|
||||
RAPIDJSON_FORCEINLINE Ch Take() { return is.Take(); }
|
||||
RAPIDJSON_FORCEINLINE void Push(char) {}
|
||||
RAPIDJSON_FORCEINLINE void Push(char) {}
|
||||
|
||||
size_t Tell() { return is.Tell(); }
|
||||
size_t Length() { return 0; }
|
||||
@ -1097,7 +1421,6 @@ private:
|
||||
typedef NumberStream<InputStream, false, false> Base;
|
||||
public:
|
||||
NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is), stackStream(reader.stack_) {}
|
||||
~NumberStream() {}
|
||||
|
||||
RAPIDJSON_FORCEINLINE Ch TakePush() {
|
||||
stackStream.Put(static_cast<char>(Base::is.Peek()));
|
||||
@ -1124,7 +1447,6 @@ private:
|
||||
typedef NumberStream<InputStream, true, false> Base;
|
||||
public:
|
||||
NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is) {}
|
||||
~NumberStream() {}
|
||||
|
||||
RAPIDJSON_FORCEINLINE Ch Take() { return Base::TakePush(); }
|
||||
};
|
||||
@ -1185,18 +1507,27 @@ private:
|
||||
}
|
||||
// Parse NaN or Infinity here
|
||||
else if ((parseFlags & kParseNanAndInfFlag) && RAPIDJSON_LIKELY((s.Peek() == 'I' || s.Peek() == 'N'))) {
|
||||
useNanOrInf = true;
|
||||
if (RAPIDJSON_LIKELY(Consume(s, 'N') && Consume(s, 'a') && Consume(s, 'N'))) {
|
||||
d = std::numeric_limits<double>::quiet_NaN();
|
||||
if (Consume(s, 'N')) {
|
||||
if (Consume(s, 'a') && Consume(s, 'N')) {
|
||||
d = std::numeric_limits<double>::quiet_NaN();
|
||||
useNanOrInf = true;
|
||||
}
|
||||
}
|
||||
else if (RAPIDJSON_LIKELY(Consume(s, 'I') && Consume(s, 'n') && Consume(s, 'f'))) {
|
||||
d = (minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
|
||||
if (RAPIDJSON_UNLIKELY(s.Peek() == 'i' && !(Consume(s, 'i') && Consume(s, 'n')
|
||||
&& Consume(s, 'i') && Consume(s, 't') && Consume(s, 'y'))))
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
|
||||
else if (RAPIDJSON_LIKELY(Consume(s, 'I'))) {
|
||||
if (Consume(s, 'n') && Consume(s, 'f')) {
|
||||
d = (minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
|
||||
useNanOrInf = true;
|
||||
|
||||
if (RAPIDJSON_UNLIKELY(s.Peek() == 'i' && !(Consume(s, 'i') && Consume(s, 'n')
|
||||
&& Consume(s, 'i') && Consume(s, 't') && Consume(s, 'y')))) {
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (RAPIDJSON_UNLIKELY(!useNanOrInf)) {
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
|
||||
}
|
||||
}
|
||||
else
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
|
||||
@ -1231,8 +1562,6 @@ private:
|
||||
// Force double for big integer
|
||||
if (useDouble) {
|
||||
while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
|
||||
if (RAPIDJSON_UNLIKELY(d >= 1.7976931348623157e307)) // DBL_MAX / 10.0
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
|
||||
d = d * 10 + (s.TakePush() - '0');
|
||||
}
|
||||
}
|
||||
@ -1302,9 +1631,18 @@ private:
|
||||
if (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
|
||||
exp = static_cast<int>(s.Take() - '0');
|
||||
if (expMinus) {
|
||||
// (exp + expFrac) must not underflow int => we're detecting when -exp gets
|
||||
// dangerously close to INT_MIN (a pessimistic next digit 9 would push it into
|
||||
// underflow territory):
|
||||
//
|
||||
// -(exp * 10 + 9) + expFrac >= INT_MIN
|
||||
// <=> exp <= (expFrac - INT_MIN - 9) / 10
|
||||
RAPIDJSON_ASSERT(expFrac <= 0);
|
||||
int maxExp = (expFrac + 2147483639) / 10;
|
||||
|
||||
while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
|
||||
exp = exp * 10 + static_cast<int>(s.Take() - '0');
|
||||
if (exp >= 214748364) { // Issue #313: prevent overflow exponent
|
||||
if (RAPIDJSON_UNLIKELY(exp > maxExp)) {
|
||||
while (RAPIDJSON_UNLIKELY(s.Peek() >= '0' && s.Peek() <= '9')) // Consume the rest of exponent
|
||||
s.Take();
|
||||
}
|
||||
@ -1363,6 +1701,13 @@ private:
|
||||
else
|
||||
d = internal::StrtodNormalPrecision(d, p);
|
||||
|
||||
// Use > max, instead of == inf, to fix bogus warning -Wfloat-equal
|
||||
if (d > (std::numeric_limits<double>::max)()) {
|
||||
// Overflow
|
||||
// TODO: internal::StrtodX should report overflow (or underflow)
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
|
||||
}
|
||||
|
||||
cont = handler.Double(minus ? -d : d);
|
||||
}
|
||||
else if (useNanOrInf) {
|
||||
@ -1408,29 +1753,31 @@ private:
|
||||
|
||||
// States
|
||||
enum IterativeParsingState {
|
||||
IterativeParsingStartState = 0,
|
||||
IterativeParsingFinishState,
|
||||
IterativeParsingErrorState,
|
||||
IterativeParsingFinishState = 0, // sink states at top
|
||||
IterativeParsingErrorState, // sink states at top
|
||||
IterativeParsingStartState,
|
||||
|
||||
// Object states
|
||||
IterativeParsingObjectInitialState,
|
||||
IterativeParsingMemberKeyState,
|
||||
IterativeParsingKeyValueDelimiterState,
|
||||
IterativeParsingMemberValueState,
|
||||
IterativeParsingMemberDelimiterState,
|
||||
IterativeParsingObjectFinishState,
|
||||
|
||||
// Array states
|
||||
IterativeParsingArrayInitialState,
|
||||
IterativeParsingElementState,
|
||||
IterativeParsingElementDelimiterState,
|
||||
IterativeParsingArrayFinishState,
|
||||
|
||||
// Single value state
|
||||
IterativeParsingValueState
|
||||
};
|
||||
IterativeParsingValueState,
|
||||
|
||||
enum { cIterativeParsingStateCount = IterativeParsingValueState + 1 };
|
||||
// Delimiter states (at bottom)
|
||||
IterativeParsingElementDelimiterState,
|
||||
IterativeParsingMemberDelimiterState,
|
||||
IterativeParsingKeyValueDelimiterState,
|
||||
|
||||
cIterativeParsingStateCount
|
||||
};
|
||||
|
||||
// Tokens
|
||||
enum Token {
|
||||
@ -1452,7 +1799,7 @@ private:
|
||||
kTokenCount
|
||||
};
|
||||
|
||||
RAPIDJSON_FORCEINLINE Token Tokenize(Ch c) {
|
||||
RAPIDJSON_FORCEINLINE Token Tokenize(Ch c) const {
|
||||
|
||||
//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
|
||||
#define N NumberToken
|
||||
@ -1479,9 +1826,21 @@ private:
|
||||
return NumberToken;
|
||||
}
|
||||
|
||||
RAPIDJSON_FORCEINLINE IterativeParsingState Predict(IterativeParsingState state, Token token) {
|
||||
RAPIDJSON_FORCEINLINE IterativeParsingState Predict(IterativeParsingState state, Token token) const {
|
||||
// current state x one lookahead token -> new state
|
||||
static const char G[cIterativeParsingStateCount][kTokenCount] = {
|
||||
// Finish(sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
// Error(sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
// Start
|
||||
{
|
||||
IterativeParsingArrayInitialState, // Left bracket
|
||||
@ -1496,18 +1855,6 @@ private:
|
||||
IterativeParsingValueState, // Null
|
||||
IterativeParsingValueState // Number
|
||||
},
|
||||
// Finish(sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
// Error(sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
// ObjectInitial
|
||||
{
|
||||
IterativeParsingErrorState, // Left bracket
|
||||
@ -1536,20 +1883,6 @@ private:
|
||||
IterativeParsingErrorState, // Null
|
||||
IterativeParsingErrorState // Number
|
||||
},
|
||||
// KeyValueDelimiter
|
||||
{
|
||||
IterativeParsingArrayInitialState, // Left bracket(push MemberValue state)
|
||||
IterativeParsingErrorState, // Right bracket
|
||||
IterativeParsingObjectInitialState, // Left curly bracket(push MemberValue state)
|
||||
IterativeParsingErrorState, // Right curly bracket
|
||||
IterativeParsingErrorState, // Comma
|
||||
IterativeParsingErrorState, // Colon
|
||||
IterativeParsingMemberValueState, // String
|
||||
IterativeParsingMemberValueState, // False
|
||||
IterativeParsingMemberValueState, // True
|
||||
IterativeParsingMemberValueState, // Null
|
||||
IterativeParsingMemberValueState // Number
|
||||
},
|
||||
// MemberValue
|
||||
{
|
||||
IterativeParsingErrorState, // Left bracket
|
||||
@ -1564,20 +1897,6 @@ private:
|
||||
IterativeParsingErrorState, // Null
|
||||
IterativeParsingErrorState // Number
|
||||
},
|
||||
// MemberDelimiter
|
||||
{
|
||||
IterativeParsingErrorState, // Left bracket
|
||||
IterativeParsingErrorState, // Right bracket
|
||||
IterativeParsingErrorState, // Left curly bracket
|
||||
IterativeParsingObjectFinishState, // Right curly bracket
|
||||
IterativeParsingErrorState, // Comma
|
||||
IterativeParsingErrorState, // Colon
|
||||
IterativeParsingMemberKeyState, // String
|
||||
IterativeParsingErrorState, // False
|
||||
IterativeParsingErrorState, // True
|
||||
IterativeParsingErrorState, // Null
|
||||
IterativeParsingErrorState // Number
|
||||
},
|
||||
// ObjectFinish(sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
@ -1612,6 +1931,18 @@ private:
|
||||
IterativeParsingErrorState, // Null
|
||||
IterativeParsingErrorState // Number
|
||||
},
|
||||
// ArrayFinish(sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
// Single Value (sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
// ElementDelimiter
|
||||
{
|
||||
IterativeParsingArrayInitialState, // Left bracket(push Element state)
|
||||
@ -1626,18 +1957,34 @@ private:
|
||||
IterativeParsingElementState, // Null
|
||||
IterativeParsingElementState // Number
|
||||
},
|
||||
// ArrayFinish(sink state)
|
||||
// MemberDelimiter
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
IterativeParsingErrorState, // Left bracket
|
||||
IterativeParsingErrorState, // Right bracket
|
||||
IterativeParsingErrorState, // Left curly bracket
|
||||
IterativeParsingObjectFinishState, // Right curly bracket
|
||||
IterativeParsingErrorState, // Comma
|
||||
IterativeParsingErrorState, // Colon
|
||||
IterativeParsingMemberKeyState, // String
|
||||
IterativeParsingErrorState, // False
|
||||
IterativeParsingErrorState, // True
|
||||
IterativeParsingErrorState, // Null
|
||||
IterativeParsingErrorState // Number
|
||||
},
|
||||
// Single Value (sink state)
|
||||
// KeyValueDelimiter
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
}
|
||||
IterativeParsingArrayInitialState, // Left bracket(push MemberValue state)
|
||||
IterativeParsingErrorState, // Right bracket
|
||||
IterativeParsingObjectInitialState, // Left curly bracket(push MemberValue state)
|
||||
IterativeParsingErrorState, // Right curly bracket
|
||||
IterativeParsingErrorState, // Comma
|
||||
IterativeParsingErrorState, // Colon
|
||||
IterativeParsingMemberValueState, // String
|
||||
IterativeParsingMemberValueState, // False
|
||||
IterativeParsingMemberValueState, // True
|
||||
IterativeParsingMemberValueState, // Null
|
||||
IterativeParsingMemberValueState // Number
|
||||
},
|
||||
}; // End of G
|
||||
|
||||
return static_cast<IterativeParsingState>(G[state][token]);
|
||||
@ -1818,6 +2165,14 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s) const {
|
||||
return s >= IterativeParsingElementDelimiterState;
|
||||
}
|
||||
|
||||
RAPIDJSON_FORCEINLINE bool IsIterativeParsingCompleteState(IterativeParsingState s) const {
|
||||
return s <= IterativeParsingErrorState;
|
||||
}
|
||||
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
ParseResult IterativeParse(InputStream& is, Handler& handler) {
|
||||
parseResult_.Clear();
|
||||
@ -1856,6 +2211,7 @@ private:
|
||||
static const size_t kDefaultStackCapacity = 256; //!< Default stack capacity in bytes for storing a single decoded string.
|
||||
internal::Stack<StackAllocator> stack_; //!< A stack for storing decoded string temporarily during non-destructive parsing.
|
||||
ParseResult parseResult_;
|
||||
IterativeParsingState state_;
|
||||
}; // class GenericReader
|
||||
|
||||
//! Reader with UTF8 encoding and default allocator.
|
||||
@ -1863,7 +2219,7 @@ typedef GenericReader<UTF8<>, UTF8<> > Reader;
|
||||
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#ifdef __clang__
|
||||
#if defined(__clang__) || defined(_MSC_VER)
|
||||
RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
@ -1872,8 +2228,4 @@ RAPIDJSON_DIAG_POP
|
||||
RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#endif // RAPIDJSON_READER_H_
|
||||
|
Reference in New Issue
Block a user