@@ -74,15 +74,8 @@ int main(int argc, char *argv[]) {
74
74
std::cout << p.size () << " B " ;
75
75
std::cout << std::endl;
76
76
}
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);
86
79
87
80
rapidjson::Document d;
88
81
@@ -98,19 +91,19 @@ int main(int argc, char *argv[]) {
98
91
.is_valid ();
99
92
if (just_favorites) {
100
93
printf (" our parser : %s \n " ,
101
- ours_correct ? " correct" : " invalid" );
94
+ (err == simdjson::error_code::SUCCESS) ? " correct" : " invalid" );
102
95
printf (" rapid (check encoding) : %s \n " ,
103
96
rapid_correct_checkencoding ? " correct" : " invalid" );
104
97
printf (" sajson : %s \n " ,
105
98
sajson_correct ? " correct" : " invalid" );
106
- if (oursreturn == simdjson::DEPTH_ERROR) {
99
+ if (err == simdjson::DEPTH_ERROR) {
107
100
printf (" simdjson encountered a DEPTH_ERROR, it was parametrized to "
108
101
" reject documents with depth exceeding %zu.\n " ,
109
- max_depth);
102
+ parser. max_depth () );
110
103
}
111
- if ((ours_correct != rapid_correct_checkencoding) ||
104
+ if (((err == simdjson::error_code::SUCCESS) != rapid_correct_checkencoding) ||
112
105
(rapid_correct_checkencoding != sajson_correct) ||
113
- (ours_correct != sajson_correct)) {
106
+ ((err == simdjson::SUCCESS) != sajson_correct)) {
114
107
printf (" WARNING: THEY DISAGREE\n\n " );
115
108
return EXIT_FAILURE;
116
109
}
@@ -137,11 +130,11 @@ int main(int argc, char *argv[]) {
137
130
if (tokens == nullptr ) {
138
131
printf (" Failed to alloc memory for jsmn\n " );
139
132
} else {
140
- jsmn_parser parser ;
141
- jsmn_init (&parser );
133
+ jsmn_parser jsmnparser ;
134
+ jsmn_init (&jsmnparser );
142
135
memcpy (buffer, p.data (), p.size ());
143
136
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 ());
145
138
tokens = nullptr ;
146
139
jsmn_correct = (r > 0 );
147
140
}
@@ -163,7 +156,7 @@ int main(int argc, char *argv[]) {
163
156
delete json_cpp_reader;
164
157
165
158
printf (" our parser : %s \n " ,
166
- ours_correct ? " correct" : " invalid" );
159
+ (err == simdjson::error_code::SUCCESS) ? " correct" : " invalid" );
167
160
printf (" rapid : %s \n " ,
168
161
rapid_correct ? " correct" : " invalid" );
169
162
printf (" rapid (check encoding) : %s \n " ,
0 commit comments