Annotate all reject code paths as unlikely
This commit is contained in:
@@ -225,7 +225,7 @@ inline WeaselJsonStatus n_value(Parser3 *self) {
|
||||
if (memcmp(self->buf, "rue", 3) == 0) {
|
||||
self->callbacks->on_true_literal(self->data);
|
||||
self->buf += 3;
|
||||
} else {
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
} else {
|
||||
@@ -241,7 +241,7 @@ inline WeaselJsonStatus n_value(Parser3 *self) {
|
||||
if (memcmp(self->buf, "alse", 4) == 0) {
|
||||
self->callbacks->on_false_literal(self->data);
|
||||
self->buf += 4;
|
||||
} else {
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
} else {
|
||||
@@ -257,7 +257,7 @@ inline WeaselJsonStatus n_value(Parser3 *self) {
|
||||
if (memcmp(self->buf, "ull", 3) == 0) {
|
||||
self->callbacks->on_null_literal(self->data);
|
||||
self->buf += 3;
|
||||
} else {
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
} else {
|
||||
@@ -267,7 +267,7 @@ inline WeaselJsonStatus n_value(Parser3 *self) {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
}
|
||||
@@ -296,7 +296,7 @@ inline WeaselJsonStatus n_object2(Parser3 *self) {
|
||||
}
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
default:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ inline WeaselJsonStatus n_object3(Parser3 *self) {
|
||||
}
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
default:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ inline WeaselJsonStatus n_array3(Parser3 *self) {
|
||||
}
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
default:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ inline WeaselJsonStatus n_string(Parser3 *self) {
|
||||
return WeaselJson_AGAIN;
|
||||
}
|
||||
}
|
||||
if (*self->buf != '"') {
|
||||
if (*self->buf != '"') [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
self->callbacks->on_begin_string(self->data);
|
||||
@@ -465,7 +465,7 @@ begin:
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
case Tables::CONTINUATION_BYTE:
|
||||
case Tables::INVALID:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,13 +494,13 @@ inline WeaselJsonStatus n_string_following_escape(Parser3 *self) {
|
||||
}
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
default:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
inline WeaselJsonStatus t_utf8_continuation_byte(Parser3 *self) {
|
||||
if (tables.stringByteMeaning[uint8_t(*self->buf)] !=
|
||||
Tables::CONTINUATION_BYTE) {
|
||||
Tables::CONTINUATION_BYTE) [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
self->utf8Codepoint <<= 6;
|
||||
@@ -512,14 +512,15 @@ inline WeaselJsonStatus t_utf8_continuation_byte(Parser3 *self) {
|
||||
|
||||
inline WeaselJsonStatus t_utf8_last_continuation_byte(Parser3 *self) {
|
||||
if (tables.stringByteMeaning[uint8_t(*self->buf)] !=
|
||||
Tables::CONTINUATION_BYTE) {
|
||||
Tables::CONTINUATION_BYTE) [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
self->utf8Codepoint <<= 6;
|
||||
self->utf8Codepoint |= *self->buf & 0b00111111;
|
||||
if (self->utf8Codepoint < self->minCodepoint ||
|
||||
self->utf8Codepoint > 0x10ffff ||
|
||||
(0xd800 <= self->utf8Codepoint && self->utf8Codepoint <= 0xdfff)) {
|
||||
(0xd800 <= self->utf8Codepoint && self->utf8Codepoint <= 0xdfff))
|
||||
[[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
// TODO tell valgrind utf8Codepoint and minCodepoint are uninitialized
|
||||
@@ -533,8 +534,9 @@ inline WeaselJsonStatus t_digit(Parser3 *self) {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
}
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
inline WeaselJsonStatus t_onenine(Parser3 *self) {
|
||||
@@ -542,8 +544,9 @@ inline WeaselJsonStatus t_onenine(Parser3 *self) {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
}
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
inline WeaselJsonStatus t_hex(Parser3 *self) {
|
||||
@@ -554,7 +557,7 @@ inline WeaselJsonStatus t_hex(Parser3 *self) {
|
||||
self->utf8Codepoint |= 10 + *self->buf - 'a';
|
||||
} else if ('A' <= *self->buf && *self->buf <= 'F') {
|
||||
self->utf8Codepoint |= 10 + *self->buf - 'A';
|
||||
} else {
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
++self->buf;
|
||||
@@ -570,7 +573,7 @@ inline WeaselJsonStatus t_hex2(Parser3 *self) {
|
||||
self->utf8Codepoint |= 10 + *self->buf - 'a';
|
||||
} else if ('A' <= *self->buf && *self->buf <= 'F') {
|
||||
self->utf8Codepoint |= 10 + *self->buf - 'A';
|
||||
} else {
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
++self->buf;
|
||||
@@ -637,12 +640,13 @@ inline WeaselJsonStatus t_hex3(Parser3 *self) {
|
||||
self->utf8Codepoint |= 10 + *self->buf - 'a';
|
||||
} else if ('A' <= *self->buf && *self->buf <= 'F') {
|
||||
self->utf8Codepoint |= 10 + *self->buf - 'A';
|
||||
} else {
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
++self->buf;
|
||||
|
||||
if (!(0xdc00 <= self->utf8Codepoint && self->utf8Codepoint <= 0xdfff)) {
|
||||
if (!(0xdc00 <= self->utf8Codepoint && self->utf8Codepoint <= 0xdfff))
|
||||
[[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
|
||||
@@ -654,7 +658,7 @@ inline WeaselJsonStatus t_hex3(Parser3 *self) {
|
||||
// there's not room, flush, write into a temp buffer, and flush again.
|
||||
char tmp[4];
|
||||
assert(self->utf8Codepoint >= 0x10000);
|
||||
if (self->utf8Codepoint > 0x10FFFF) {
|
||||
if (self->utf8Codepoint > 0x10FFFF) [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
bool useTmp = self->buf - self->writeBuf < 4;
|
||||
@@ -710,7 +714,7 @@ inline WeaselJsonStatus n_integer(Parser3 *self) {
|
||||
}
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
default:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,7 +740,7 @@ inline WeaselJsonStatus n_integer2(Parser3 *self) {
|
||||
}
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
default:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -759,7 +763,7 @@ inline WeaselJsonStatus n_digits(Parser3 *self) {
|
||||
}
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
default:
|
||||
return WeaselJson_REJECT;
|
||||
[[unlikely]] return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -852,8 +856,9 @@ inline WeaselJsonStatus n_true(Parser3 *self) {
|
||||
self->pop();
|
||||
self->callbacks->on_true_literal(self->data);
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
}
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
inline WeaselJsonStatus n_false(Parser3 *self) {
|
||||
@@ -862,8 +867,9 @@ inline WeaselJsonStatus n_false(Parser3 *self) {
|
||||
self->pop();
|
||||
self->callbacks->on_false_literal(self->data);
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
}
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
inline WeaselJsonStatus n_null(Parser3 *self) {
|
||||
@@ -872,8 +878,9 @@ inline WeaselJsonStatus n_null(Parser3 *self) {
|
||||
self->pop();
|
||||
self->callbacks->on_null_literal(self->data);
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
}
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
template <char kChar, bool kSkipWhitespace = false>
|
||||
@@ -891,12 +898,13 @@ inline WeaselJsonStatus singleChar(Parser3 *self) {
|
||||
++self->buf;
|
||||
self->pop();
|
||||
MUSTTAIL return Parser3::keepGoing(self);
|
||||
}
|
||||
} else [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
inline WeaselJsonStatus t_eof(Parser3 *self) {
|
||||
if (self->len() > 0) {
|
||||
if (self->len() > 0) [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
return self->complete ? WeaselJson_OK : WeaselJson_AGAIN;
|
||||
@@ -1053,7 +1061,7 @@ inline WeaselJsonStatus Parser3::keepGoing(Parser3 *self) {
|
||||
}
|
||||
return WeaselJson_AGAIN;
|
||||
}
|
||||
if (!symbolTables.acceptsEmptyString[self->top()]) {
|
||||
if (!symbolTables.acceptsEmptyString[self->top()]) [[unlikely]] {
|
||||
return WeaselJson_REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user