8000 Updating allparserscheckfile · JavaScriptExpert/simdjson@8f3ddd3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f3ddd3

Browse files
committed
Updating allparserscheckfile
1 parent 8f34e67 commit 8f3ddd3

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

tests/allparserscheckfile.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,8 @@ int main(int argc, char *argv[]) {
7474
std::cout << p.size() << " B ";
7575
std::cout << std::endl;
7676
}
77-
simdjson::ParsedJson pj;
78-
size_t max_depth = 1024 * 4;
79-
bool allocok = pj.allocate_capacity(p.size(), max_depth);
80-
if (!allocok) {
81-
std::cerr << "can't allocate memory" << std::endl;
82-
return EXIT_FAILURE;
83-
}
84-
int oursreturn = json_parse(p, pj);
85-
bool ours_correct = (oursreturn == 0); // returns 0 on success
77+
simdjson::document::parser parser;
78+
auto [doc, err] = parser.parse(p);
8679

8780
rapidjson::Document d;
8881

@@ -98,19 +91,19 @@ int main(int argc, char *argv[]) {
9891
.is_valid();
9992
if (just_favorites) {
10093
printf("our parser : %s \n",
101-
ours_correct ? "correct" : "invalid");
94+
(err == simdjson::error_code::SUCCESS) ? "correct" : "invalid");
10295
printf("rapid (check encoding) : %s \n",
10396
rapid_correct_checkencoding ? "correct" : "invalid");
10497
printf("sajson : %s \n",
10598
sajson_correct ? "correct" : "invalid");
106-
if (oursreturn == simdjson::DEPTH_ERROR) {
99+
if (err == simdjson::DEPTH_ERROR) {
107100
printf("simdjson encountered a DEPTH_ERROR, it was parametrized to "
108101
"reject documents with depth exceeding %zu.\n",
109-
max_depth);
102+
parser.max_depth());
110103
}
111-
if ((ours_correct != rapid_correct_checkencoding) ||
104+
if (((err == simdjson::error_code::SUCCESS) != rapid_correct_checkencoding) ||
112105
(rapid_correct_checkencoding != sajson_correct) ||
113-
(ours_correct != sajson_correct)) {
106+
((err == simdjson::SUCCESS) != sajson_correct)) {
114107
printf("WARNING: THEY DISAGREE\n\n");
115108
return EXIT_FAILURE;
116109
}
@@ -137,11 +130,11 @@ int main(int argc, char *argv[]) {
137130
if (tokens == nullptr) {
138131
printf("Failed to alloc memory for jsmn\n");
139132
} else {
140-
jsmn_parser parser;
141-
jsmn_init(&parser);
133+
jsmn_parser jsmnparser;
134+
jsmn_init(&jsmnparser);
142135
memcpy(buffer, p.data(), p.size());
143136
buffer[p.size()] = '\0';
144-
int r = jsmn_parse(&parser, buffer, p.size(), tokens.get(), p.size());
137+
int r = jsmn_parse(&jsmnparser, buffer, p.size(), tokens.get(), p.size());
145138
tokens = nullptr;
146139
jsmn_correct = (r > 0);
147140
}
@@ -163,7 +156,7 @@ int main(int argc, char *argv[]) {
163156
delete json_cpp_reader;
164157

165158
printf("our parser : %s \n",
166-
ours_correct ? "correct" : "invalid");
159+
(err == simdjson::error_code::SUCCESS) ? "correct" : "invalid");
167160
printf("rapid : %s \n",
168161
rapid_correct ? "correct" : "invalid");
169162
printf("rapid (check encoding) : %s \n",

0 commit comments

Comments
 (0)
0