Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort the conditional statements #946

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions ext/oj/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,26 +681,28 @@ void oj_parse2(ParseInfo pi) {
pi->cur = pi->json;
err_init(&pi->err);
while (1) {
if (0 < pi->max_depth && pi->max_depth <= pi->stack.tail - pi->stack.head - 1) {
if (RB_UNLIKELY(0 < pi->max_depth && pi->max_depth <= pi->stack.tail - pi->stack.head - 1)) {
VALUE err_clas = oj_get_json_err_class("NestingError");

oj_set_error_at(pi, err_clas, __FILE__, __LINE__, "Too deeply nested.");
pi->err_class = err_clas;
return;
}
next_non_white(pi);
if (!first && '\0' != *pi->cur) {
oj_set_error_at(pi,
oj_parse_error_class,
__FILE__,
__LINE__,
"unexpected characters after the JSON document");
}

// If no tokens are consumed (i.e. empty string), throw a parse error
// this is the behavior of JSON.parse in both Ruby and JS.
if (No == pi->options.empty_string && 1 == first && '\0' == *pi->cur) {
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
if (first) {
// If no tokens are consumed (i.e. empty string), throw a parse error
// this is the behavior of JSON.parse in both Ruby and JS.
if (RB_UNLIKELY('\0' == *pi->cur && No == pi->options.empty_string)) {
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
}
} else {
if (RB_UNLIKELY('\0' != *pi->cur)) {
oj_set_error_at(pi,
oj_parse_error_class,
__FILE__,
__LINE__,
"unexpected characters after the JSON document");
}
}

switch (*pi->cur++) {
Expand Down Expand Up @@ -761,7 +763,7 @@ void oj_parse2(ParseInfo pi) {
case '\0': pi->cur--; return;
default: oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character"); return;
}
if (err_has(&pi->err)) {
if (RB_UNLIKELY(err_has(&pi->err))) {
return;
}
if (stack_empty(&pi->stack)) {
Expand Down
Loading