8000 Use parse_primitive (negative perf!) · JavaScriptExpert/simdjson@03aaf18 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03aaf18

Browse files
committed
Use parse_primitive (negative perf!)
1 parent 6ef9395 commit 03aaf18

File tree

2 files changed

+55
-48
lines changed

2 files changed

+55
-48
lines changed

src/generic/stage2/structural_parser.h

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -123,34 +123,27 @@ WARN_UNUSED really_inline error_code structural_parser::parse(T &builder) noexce
123123
{
124124
const uint8_t *value = advance();
125125
switch (*value) {
126-
case '{': {
127-
if (empty_object(builder)) { goto document_end; }
128-
SIMDJSON_TRY( start_object(builder) );
129-
goto object_begin;
130-
}
131-
cas 8000 e '[': {
132-
if (empty_array(builder)) { goto document_end; }
133-
SIMDJSON_TRY( start_array(builder) );
134-
// Make sure the outer array is closed before continuing; otherwise, there are ways we could get
135-
// into memory corruption. See https://github.com/simdjson/simdjson/issues/906
136-
if (!STREAMING) {
137-
if (buf[dom_parser.structural_indexes[dom_parser.n_structural_indexes - 1]] != ']') {
138-
return TAPE_ERROR;
126+
case '{': {
127+
if (empty_object(builder)) { goto document_end; }
128+
SIMDJSON_TRY( start_object(builder) );
129+
goto object_begin;
130+
}
131+
case '[': {
132+
if (empty_array(builder)) { goto document_end; }
133+
SIMDJSON_TRY( start_array(builder) );
134+
// Make sure the outer array is closed before continuing; otherwise, there are ways we could get
135+
// into memory corruption. See https://github.com/simdjson/simdjson/issues/906
136+
if (!STREAMING) {
137+
if (buf[dom_parser.structural_indexes[dom_parser.n_structural_indexes - 1]] != ']') {
138+
return TAPE_ERROR;
139+
}
139140
}
141+
goto array_begin;
142+
}
143+
default: {
144+
SIMDJSON_TRY( builder.parse_root_primitive(*this, value) );
145+
goto document_end;
140146
}
141-
goto array_begin;
142-
}
143-
case '"': SIMDJSON_TRY( builder.parse_string(*this, value) ); goto document_end;
144-
case 't': SIMDJSON_TRY( builder.parse_root_true_atom(*this, value) ); goto document_end;
145-
case 'f': SIMDJSON_TRY( builder.parse_root_false_atom(*this, value) ); goto document_end;
146-
case 'n': SIMDJSON_TRY( builder.parse_root_null_atom(*this, value) ); goto document_end;
147-
case '-':
148-
case '0': case '1': case '2': case '3': case '4':
149-
case '5': case '6': case '7': case '8': case '9':
150-
SIMDJSON_TRY( builder.parse_root_number(*this, value) ); goto document_end;
151-
default:
152-
log_error("Document starts with a non-value character");
153-
return TAPE_ERROR;
154147
}
155148
}
156149

@@ -182,17 +175,9 @@ object_field: {
182175
SIMDJSON_TRY( start_array(builder) );
183176
goto array_begin;
184177
}
185-
case '"': SIMDJSON_TRY( builder.parse_string(*this, value) ); break;
186-
case 't': SIMDJSON_TRY( builder.parse_true_atom(*this, value) ); break;
187-
case 'f': SIMDJSON_TRY( builder.parse_false_atom(*this, value) ); break;
188-
case 'n': SIMDJSON_TRY( builder.parse_null_atom(*this, value) ); break;
189-
case '-':
190-
case '0': case '1': case '2': case '3': case '4':
191-
case '5': case '6': case '7': case '8': case '9':
192-
SIMDJSON_TRY( builder.parse_number(*this, value) ); break;
193-
default:
194-
log_error("Non-value found when value was expected!");
195-
return TAPE_ERROR;
178+
default: {
179+
SIMDJSON_TRY( builder.parse_primitive(*this, value) );
180+
}
196181
}
197182
} // object_field:
198183

@@ -241,17 +226,9 @@ array_value: {
241226
SIMDJSON_TRY( start_array(builder) );
242227
goto array_begin;
243228
}
244-
case '"': SIMDJSON_TRY( builder.parse_string(*this, value) ); break;
245-
case 't&# 6D40 39;: SIMDJSON_TRY( builder.parse_true_atom(*this, value) ); break;
246-
case 'f': SIMDJSON_TRY( builder.parse_false_atom(*this, value) ); break;
247-
case 'n': SIMDJSON_TRY( builder.parse_null_atom(*this, value) ); break;
248-
case '-':
249-
case '0': case '1': case '2': case '3': case '4':
250-
case '5': case '6': case '7': case '8': case '9':
251-
SIMDJSON_TRY( builder.parse_number(*this, value) ); break;
252-
default:
253-
log_error("Non-value found when value was expected!");
254-
return TAPE_ERROR;
229+
default: {
230+
SIMDJSON_TRY( builder.parse_primitive(*this, value) );
231+
}
255232
}
256233
} // array_value:
257234

src/generic/stage2/tape_builder.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,36 @@ struct tape_builder {
1616
private:
1717
friend struct structural_parser;
1818

19+
really_inline error_code parse_root_primitive(structural_parser &parser, const uint8_t *value) {
20+
switch (*value) {
21+
case '"': return parse_string(parser, value);
22+
case 't': return parse_root_true_atom(parser, value);
23+
case 'f': return parse_root_false_atom(parser, value);
24+
case 'n': return parse_root_null_atom(parser, value);
25+
case '-':
26+
case '0': case '1': case '2': case '3': case '4':
27+
case '5': case '6': case '7': case '8': case '9':
28+
return parse_root_number(parser, value);
29+
default:
30+
parser.log_error("Document starts with a non-value character");
31+
return TAPE_ERROR;
32+
}
33+
}
34+
really_inline error_code parse_primitive(structural_parser &parser, const uint8_t *value) {
35+
switch (*value) {
36+
case '"': return parse_string(parser, value);
37+
case 't': return parse_true_atom(parser, value);
38+
case 'f': return parse_false_atom(parser, value);
39+
case 'n': return parse_null_atom(parser, value);
40+
case '-':
41+
case '0': case '1': case '2': case '3': case '4':
42+
case '5': case '6': case '7': case '8': case '9':
43+
return parse_number(parser, value);
44+
default:
45+
parser.log_error("Non-value found when value was expected!");
46+
return TAPE_ERROR;
47+
}
48+
}
1949
really_inline void empty_object(structural_parser &parser) {
2050
parser.log_value("empty object");
2151
empty_container(parser, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);

0 commit comments

Comments
 (0)
0