Reduce times of stack size check; reduce transition table size.
This commit is contained in:
parent
1f53c6c041
commit
b22a89bf3f
@ -572,7 +572,7 @@ private:
|
|||||||
Ch e = is.Take();
|
Ch e = is.Take();
|
||||||
if ((sizeof(Ch) == 1 || unsigned(e) < 256) && escape[(unsigned char)e]) {
|
if ((sizeof(Ch) == 1 || unsigned(e) < 256) && escape[(unsigned char)e]) {
|
||||||
if (!(parseFlags & kParseInsituFlag)) {
|
if (!(parseFlags & kParseInsituFlag)) {
|
||||||
if (!IsStackSpaceSufficient<Ch>(1)) {
|
if (!CheckStackSpaceQuota(sizeof(Ch))) {
|
||||||
RAPIDJSON_PARSE_ERROR(kParseErrorStackSizeLimitExceeded, is.Tell() - 1);
|
RAPIDJSON_PARSE_ERROR(kParseErrorStackSizeLimitExceeded, is.Tell() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -597,7 +597,7 @@ private:
|
|||||||
else if (c == '"') { // Closing double quote
|
else if (c == '"') { // Closing double quote
|
||||||
is.Take();
|
is.Take();
|
||||||
if (!(parseFlags & kParseInsituFlag)) {
|
if (!(parseFlags & kParseInsituFlag)) {
|
||||||
if (!IsStackSpaceSufficient<Ch>(1)) {
|
if (!CheckStackSpaceQuota(sizeof(Ch))) {
|
||||||
RAPIDJSON_PARSE_ERROR(kParseErrorStackSizeLimitExceeded, is.Tell() - 1);
|
RAPIDJSON_PARSE_ERROR(kParseErrorStackSizeLimitExceeded, is.Tell() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -865,7 +865,7 @@ private:
|
|||||||
|
|
||||||
IterativeParsingState Predict(IterativeParsingState state, IterativeParsingToken token) {
|
IterativeParsingState Predict(IterativeParsingState state, IterativeParsingToken token) {
|
||||||
// current state x one lookahead token -> new state
|
// current state x one lookahead token -> new state
|
||||||
static const IterativeParsingState G[cIterativeParsingStateCount][cIterativeParsingTokenCount] = {
|
static const char G[cIterativeParsingStateCount][cIterativeParsingTokenCount] = {
|
||||||
// Start
|
// Start
|
||||||
{
|
{
|
||||||
IterativeParsingArrayInitialState, // Left bracket
|
IterativeParsingArrayInitialState, // Left bracket
|
||||||
@ -1018,7 +1018,7 @@ private:
|
|||||||
}
|
}
|
||||||
}; // End of G
|
}; // End of G
|
||||||
|
|
||||||
return G[state][token];
|
return (IterativeParsingState)G[state][token];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make an advance in the token stream and state based on the candidate destination state which was returned by Transit().
|
// Make an advance in the token stream and state based on the candidate destination state which was returned by Transit().
|
||||||
@ -1049,17 +1049,14 @@ private:
|
|||||||
n = IterativeParsingElementState;
|
n = IterativeParsingElementState;
|
||||||
else if (src == IterativeParsingKeyValueDelimiterState)
|
else if (src == IterativeParsingKeyValueDelimiterState)
|
||||||
n = IterativeParsingMemberValueState;
|
n = IterativeParsingMemberValueState;
|
||||||
// Push current state.
|
// Check stack space limit.
|
||||||
if (!IsStackSpaceSufficient<IterativeParsingState>(1)) {
|
if (!CheckStackSpaceQuota(sizeof(IterativeParsingState) + sizeof(int))) {
|
||||||
RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorStackSizeLimitExceeded, is.Tell());
|
RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorStackSizeLimitExceeded, is.Tell());
|
||||||
return IterativeParsingErrorState;
|
return IterativeParsingErrorState;
|
||||||
}
|
}
|
||||||
|
// Push current state.
|
||||||
*stack_.template Push<IterativeParsingState>(1) = n;
|
*stack_.template Push<IterativeParsingState>(1) = n;
|
||||||
// Initialize and push the member/element count.
|
// Initialize and push the member/element count.
|
||||||
if (!IsStackSpaceSufficient<int>(1)) {
|
|
||||||
RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorStackSizeLimitExceeded, is.Tell());
|
|
||||||
return IterativeParsingErrorState;
|
|
||||||
}
|
|
||||||
*stack_.template Push<int>(1) = 0;
|
*stack_.template Push<int>(1) = 0;
|
||||||
// Call handler
|
// Call handler
|
||||||
if (dst == IterativeParsingObjectInitialState)
|
if (dst == IterativeParsingObjectInitialState)
|
||||||
@ -1226,9 +1223,8 @@ private:
|
|||||||
return parseResult_;
|
return parseResult_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
bool CheckStackSpaceQuota(size_t size) const {
|
||||||
bool IsStackSpaceSufficient(size_t count) const {
|
return kStackSizeLimit == 0 || (stack_.GetSize() + size <= kStackSizeLimit);
|
||||||
return kStackSizeLimit == 0 || (stack_.GetSize() + sizeof(T) * count <= kStackSizeLimit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const size_t kDefaultStackCapacity = 256; //!< Default stack capacity in bytes for storing a single decoded string.
|
static const size_t kDefaultStackCapacity = 256; //!< Default stack capacity in bytes for storing a single decoded string.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user