Implemented feature as in #560 (ints/doubles as strings)#564
Conversation
9c72fb9 to
f761744
Compare
|
I think:
|
|
Some code fragments can be eliminated without breaking the validation rules but it does not seem much can be done. For example, code like this can be excluded: However, it is not in any tight loop and disabling anything from the parsing code will break JSON validation rules (may be a subject to yet another flag but not this one). It seems, the encoding unit tests are broken because of this line: What is the proper way to treat encoding of input & output streams? |
|
As example, the following code involving // Parse int: zero / ( digit1-9 *DIGIT )
unsigned i = 0;
uint64_t i64 = 0;
bool use64bit = false;
int significandDigit = 0;
if (RAPIDJSON_UNLIKELY(s.Peek() == '0')) {
i = 0;
s.TakePush();
}
else if (RAPIDJSON_LIKELY(s.Peek() >= '1' && s.Peek() <= '9')) {
i = static_cast<unsigned>(s.TakePush() - '0');
if (minus)
while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
if (RAPIDJSON_UNLIKELY(i >= 214748364)) { // 2^31 = 2147483648
if (RAPIDJSON_LIKELY(i != 214748364 || s.Peek() > '8')) {
i64 = i;
use64bit = true;
break;
}
}
i = i * 10 + static_cast<unsigned>(s.TakePush() - '0');
significandDigit++;
}For the following line: It should only be possible for insitu stream. For other streams, you cannot get pointers to the current position (such as a file stream). I think you should make use of existing And I will suggest appending |
|
Besides, I think new unit tests are necessary as well. |
|
Do you mean something like this? |
06a4a0b to
1d72d9c
Compare
6707351 to
8430fc0
Compare
8430fc0 to
57eae55
Compare
|
Unit tests added. |
|
Zero-termination in in-situ mode seems problematic. Consider this valid json fragment: Inserting |
|
Yes, you are right. there is no |
Implemented feature as in #560 (ints/doubles as strings)
|
Thank you for your contribution. |
Fast parsing of ints/doubles as strings as described in #560
Note: the null-termination character is never added, always use explicit length