Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3d7718

Browse files
committed
Simplify value switch statements
1 parent 9eccd7b commit e3d7718

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

‎src/generic/stage2/structural_parser.h

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,20 @@ WARN_UNUSED really_inline error_code structural_parser::parse(T &builder) noexce
115115
{
116116
const uint8_t *value = advance();
117117
switch (*value) {
118-
case '{': {
119-
if (empty_object(builder)) { goto document_end; }
120-
goto object_begin;
121-
}
118+
case '{': if (!empty_object(builder)) { goto object_begin; }; break;
122119
case '[': {
123-
if (empty_array(builder)) { goto document_end; }
124120
// Make sure the outer array is closed before continuing; otherwise, there are ways we could get
125121
// into memory corruption. See https://github.com/simdjson/simdjson/issues/906
126122
if (!STREAMING) {
127123
if (buf[dom_parser.structural_indexes[dom_parser.n_structural_indexes - 1]] != ']') {
128124
return TAPE_ERROR;
129125
}
130126
}
131-
goto array_begin;
132-
}
133-
default: {
134-
SIMDJSON_TRY( builder.parse_root_primitive(*this, value) );
135-
goto document_end;
127+
if (!empty_array(builder)) { goto array_begin; }; break;
136128
}
129+
default: SIMDJSON_TRY( builder.parse_root_primitive(*this, value) );
137130
}
131+
goto document_end;
138132
}
139133

140134
//
@@ -160,17 +154,9 @@ object_field: {
160154
if (unlikely( advance_char() != ':' )) { log_error("Missing colon after key in object"); return TAPE_ERROR; }
161155
const uint8_t *value = advance();
162156
switch (*value) {
163-
case '{': {
164-
if (empty_object(builder)) { break; };
165-
goto object_begin;
166-
}
167-
case '[': {
168-
if (empty_array(builder)) { break; };
169-
goto array_begin;
170-
}
171-
default: {
172-
SIMDJSON_TRY( builder.parse_primitive(*this, value) );
173-
}
157+
case '{': if (!empty_object(builder)) { goto object_begin; }; break;
158+
case '[': if (!empty_array(builder)) { goto array_begin; }; break;
159+
default: SIMDJSON_TRY( builder.parse_primitive(*this, value) );
174160
}
175161
} // object_field:
176162

@@ -214,17 +200,9 @@ array_begin: {
214200
array_value: {
215201
const uint8_t *value = advance();
216202
switch (*value) {
217-
case '{': {
218-
if (empty_object(builder)) { break; };
219-
goto object_begin;
220-
}
221-
case '[': {
222-
if (empty_array(builder)) { break; };
223-
goto array_begin;
224-
}
225-
default: {
226-
SIMDJSON_TRY( builder.parse_primitive(*this, value) );
227-
}
203+
case '{': if (!empty_object(builder)) { goto object_begin; }; break;
204+
case '[': if (!empty_array(builder)) { goto array_begin; }; break;
205+
default: SIMDJSON_TRY( builder.parse_primitive(*this, value) );
228206
}
229207
} // array_value:
230208

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /