Unroll whitespace-skipping loop
This commit is contained in:
@@ -750,17 +750,33 @@ struct Parser3 {
|
|||||||
Utf8Dfa strDfa;
|
Utf8Dfa strDfa;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline PRESERVE_NONE WeaselJsonStatus skipWhitespace(char *&buf, char *bufEnd) {
|
||||||
|
constexpr int kStride = 4;
|
||||||
|
for (;;) {
|
||||||
|
if (bufEnd - buf < kStride) [[unlikely]] {
|
||||||
|
while (buf != bufEnd && tables.whitespace[uint8_t(*buf)]) {
|
||||||
|
++buf;
|
||||||
|
}
|
||||||
|
return buf == bufEnd ? WeaselJson_AGAIN : WeaselJson_OK;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < kStride; ++i) {
|
||||||
|
if (tables.whitespace[uint8_t(*buf)]) {
|
||||||
|
++buf;
|
||||||
|
} else {
|
||||||
|
return WeaselJson_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline PRESERVE_NONE WeaselJsonStatus n_whitespace(Parser3 *self, char *buf,
|
inline PRESERVE_NONE WeaselJsonStatus n_whitespace(Parser3 *self, char *buf,
|
||||||
char *bufEnd) {
|
char *bufEnd) {
|
||||||
if (bufEnd - buf == 0) {
|
if (buf == bufEnd) {
|
||||||
self->pop();
|
self->pop();
|
||||||
MUSTTAIL return Parser3::keepGoing(self, buf, bufEnd);
|
MUSTTAIL return Parser3::keepGoing(self, buf, bufEnd);
|
||||||
}
|
}
|
||||||
while (tables.whitespace[uint8_t(*buf)]) {
|
if (auto s = skipWhitespace(buf, bufEnd)) {
|
||||||
++buf;
|
return s;
|
||||||
if (buf == bufEnd) {
|
|
||||||
return WeaselJson_AGAIN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self->pop();
|
self->pop();
|
||||||
MUSTTAIL return Parser3::keepGoing(self, buf, bufEnd);
|
MUSTTAIL return Parser3::keepGoing(self, buf, bufEnd);
|
||||||
@@ -856,11 +872,8 @@ inline PRESERVE_NONE WeaselJsonStatus scan_string(Parser3 *self, char *buf,
|
|||||||
inline PRESERVE_NONE WeaselJsonStatus n_value(Parser3 *self, char *buf,
|
inline PRESERVE_NONE WeaselJsonStatus n_value(Parser3 *self, char *buf,
|
||||||
char *bufEnd) {
|
char *bufEnd) {
|
||||||
assert(bufEnd - buf != 0);
|
assert(bufEnd - buf != 0);
|
||||||
while (tables.whitespace[uint8_t(*buf)]) {
|
if (auto s = skipWhitespace(buf, bufEnd)) {
|
||||||
++buf;
|
return s;
|
||||||
if (buf == bufEnd) {
|
|
||||||
return WeaselJson_AGAIN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch (*buf) {
|
switch (*buf) {
|
||||||
case '{':
|
case '{':
|
||||||
@@ -963,11 +976,8 @@ inline PRESERVE_NONE WeaselJsonStatus n_value(Parser3 *self, char *buf,
|
|||||||
inline PRESERVE_NONE WeaselJsonStatus n_object2(Parser3 *self, char *buf,
|
inline PRESERVE_NONE WeaselJsonStatus n_object2(Parser3 *self, char *buf,
|
||||||
char *bufEnd) {
|
char *bufEnd) {
|
||||||
assert(bufEnd - buf != 0);
|
assert(bufEnd - buf != 0);
|
||||||
while (tables.whitespace[uint8_t(*buf)]) {
|
if (auto s = skipWhitespace(buf, bufEnd)) {
|
||||||
++buf;
|
return s;
|
||||||
if (buf == bufEnd) {
|
|
||||||
return WeaselJson_AGAIN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch (*buf) {
|
switch (*buf) {
|
||||||
case '}':
|
case '}':
|
||||||
@@ -992,11 +1002,8 @@ inline PRESERVE_NONE WeaselJsonStatus n_object2(Parser3 *self, char *buf,
|
|||||||
inline PRESERVE_NONE WeaselJsonStatus n_object3(Parser3 *self, char *buf,
|
inline PRESERVE_NONE WeaselJsonStatus n_object3(Parser3 *self, char *buf,
|
||||||
char *bufEnd) {
|
char *bufEnd) {
|
||||||
assert(bufEnd - buf != 0);
|
assert(bufEnd - buf != 0);
|
||||||
while (tables.whitespace[uint8_t(*buf)]) {
|
if (auto s = skipWhitespace(buf, bufEnd)) {
|
||||||
++buf;
|
return s;
|
||||||
if (buf == bufEnd) {
|
|
||||||
return WeaselJson_AGAIN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch (*buf) {
|
switch (*buf) {
|
||||||
case '}':
|
case '}':
|
||||||
@@ -1019,11 +1026,8 @@ inline PRESERVE_NONE WeaselJsonStatus n_object3(Parser3 *self, char *buf,
|
|||||||
inline PRESERVE_NONE WeaselJsonStatus n_array2(Parser3 *self, char *buf,
|
inline PRESERVE_NONE WeaselJsonStatus n_array2(Parser3 *self, char *buf,
|
||||||
char *bufEnd) {
|
char *bufEnd) {
|
||||||
assert(bufEnd - buf != 0);
|
assert(bufEnd - buf != 0);
|
||||||
while (tables.whitespace[uint8_t(*buf)]) {
|
if (auto s = skipWhitespace(buf, bufEnd)) {
|
||||||
++buf;
|
return s;
|
||||||
if (buf == bufEnd) {
|
|
||||||
return WeaselJson_AGAIN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch (*buf) {
|
switch (*buf) {
|
||||||
case ']':
|
case ']':
|
||||||
@@ -1043,11 +1047,8 @@ inline PRESERVE_NONE WeaselJsonStatus n_array2(Parser3 *self, char *buf,
|
|||||||
inline PRESERVE_NONE WeaselJsonStatus n_array3(Parser3 *self, char *buf,
|
inline PRESERVE_NONE WeaselJsonStatus n_array3(Parser3 *self, char *buf,
|
||||||
char *bufEnd) {
|
char *bufEnd) {
|
||||||
assert(bufEnd - buf != 0);
|
assert(bufEnd - buf != 0);
|
||||||
while (tables.whitespace[uint8_t(*buf)]) {
|
if (auto s = skipWhitespace(buf, bufEnd)) {
|
||||||
++buf;
|
return s;
|
||||||
if (buf == bufEnd) {
|
|
||||||
return WeaselJson_AGAIN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch (*buf) {
|
switch (*buf) {
|
||||||
case ']':
|
case ']':
|
||||||
@@ -1070,11 +1071,8 @@ inline PRESERVE_NONE WeaselJsonStatus n_array3(Parser3 *self, char *buf,
|
|||||||
inline PRESERVE_NONE WeaselJsonStatus n_string(Parser3 *self, char *buf,
|
inline PRESERVE_NONE WeaselJsonStatus n_string(Parser3 *self, char *buf,
|
||||||
char *bufEnd) {
|
char *bufEnd) {
|
||||||
assert(bufEnd - buf != 0);
|
assert(bufEnd - buf != 0);
|
||||||
while (tables.whitespace[uint8_t(*buf)]) {
|
if (auto s = skipWhitespace(buf, bufEnd)) {
|
||||||
++buf;
|
return s;
|
||||||
if (buf == bufEnd) {
|
|
||||||
return WeaselJson_AGAIN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (*buf != '"') [[unlikely]] {
|
if (*buf != '"') [[unlikely]] {
|
||||||
return WeaselJson_REJECT;
|
return WeaselJson_REJECT;
|
||||||
@@ -1318,11 +1316,8 @@ inline PRESERVE_NONE WeaselJsonStatus singleChar(Parser3 *self, char *buf,
|
|||||||
char *bufEnd) {
|
char *bufEnd) {
|
||||||
if constexpr (kSkipWhitespace) {
|
if constexpr (kSkipWhitespace) {
|
||||||
assert(bufEnd - buf != 0);
|
assert(bufEnd - buf != 0);
|
||||||
while (tables.whitespace[uint8_t(*buf)]) {
|
if (auto s = skipWhitespace(buf, bufEnd)) {
|
||||||
++buf;
|
return s;
|
||||||
if (buf == bufEnd) {
|
|
||||||
return WeaselJson_AGAIN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*buf == kChar) {
|
if (*buf == kChar) {
|
||||||
|
|||||||
Reference in New Issue
Block a user