@@ -190,61 +190,65 @@ static rfl::Result<FeatureCollection> read_using_rapidjson(
190
190
// ----------------------------------------------------------------------------
191
191
// simdjson
192
192
193
- std::vector<std::vector<std::tuple<double , double >>> simdjson_to_coordinates (
193
+ simdjson_inline std::vector<std::vector<std::tuple<double , double >>> simdjson_to_coordinates (
194
194
simdjson::ondemand::array _val);
195
195
196
- Property simdjson_to_property (simdjson::ondemand::object _val);
196
+ simdjson_inline Property simdjson_to_property (simdjson::ondemand::object _val);
197
197
198
- Geometry simdjson_to_geometry (simdjson::ondemand::object _val);
198
+ simdjson_inline Geometry simdjson_to_geometry (simdjson::ondemand::object _val);
199
199
200
- Feature simdjson_to_feature (simdjson::ondemand::object _val);
200
+ simdjson_inline Feature simdjson_to_feature (simdjson::ondemand::object _val);
201
201
202
- FeatureCollection simdjson_to_feature_collection (
202
+ simdjson_inline FeatureCollection simdjson_to_feature_collection (
203
203
simdjson::ondemand::object _val);
204
204
205
- std::vector<std::vector<std::tuple<double , double >>> simdjson_to_coordinates (
205
+ simdjson_inline std::vector<std::vector<std::tuple<double , double >>> simdjson_to_coordinates (
206
206
simdjson::ondemand::array _val) {
207
207
std::vector<std::vector<std::tuple<double , double >>> coordinates;
208
208
for (auto arr1 : _val) {
209
209
std::vector<std::tuple<double , double >> vec;
210
- for (auto val2 : arr1.get_array ()) {
211
- auto arr2 = val2.get_array ();
212
- std::tuple<double , double > tup;
213
- std::get<0 >(tup) = arr2.at (0 ).get_double ();
214
- std::get<1 >(tup) = arr2.at (1 ).get_double ();
215
- vec.emplace_back (std::move (tup));
210
+ for (auto val2 : arr1) {
211
+ // Instead of indexing x = val2[0] and y = val2[1], we iterate through the two values.
212
+ auto coord = val2.begin ();
213
+ double x = *coord;
214
+ ++coord;
215
+ double y = *coord;
216
+ vec.emplace_back (x, y);
216
217
}
217
218
coordinates.emplace_back (std::move (vec));
218
219
}
219
220
return coordinates;
220
221
}
221
222
222
- Property simdjson_to_property (simdjson::ondemand::object _val) {
223
+ simdjson_inline std::string simdjson_to_string (simdjson::ondemand::value _val) {
224
+ return std::string (std::string_view (_val));
225
+ }
226
+
227
+ simdjson_inline Property simdjson_to_property (simdjson::ondemand::object _val) {
223
228
Property property;
224
- property.name = _val[" name" ]. get_string (). value ( );
229
+ property.name = std::string_view ( _val[" name" ]);
225
230
return property;
226
231
}
227
232
228
- Geometry simdjson_to_geometry (simdjson::ondemand::object _val) {
233
+ simdjson_inline Geometry simdjson_to_geometry (simdjson::ondemand::object _val) {
229
234
Geometry geometry;
230
- geometry.type = std::string (_val[" type" ].get_string ().value ());
231
- geometry.coordinates =
232
- simdjson_to_coordinates (_val[" coordinates" ].get_array ());
235
+ geometry.type = simdjson_to_string (_val[" type" ]);
236
+ geometry.coordinates = simdjson_to_coordinates (_val[" coordinates" ]);
233
237
return geometry;
234
238
}
235
239
236
- Feature simdjson_to_feature (simdjson::ondemand::object _val) {
240
+ simdjson_inline Feature simdjson_to_feature (simdjson::ondemand::object _val) {
237
241
Feature feature;
238
- feature.type = std::string (_val[" type" ]. get_string (). value () );
239
- feature.properties = simdjson_to_property (_val[" properties" ]. get_object () );
240
- feature.geometry = simdjson_to_geometry (_val[" geometry" ]. get_object () );
242
+ feature.type = simdjson_to_string (_val[" type" ]);
243
+ feature.properties = simdjson_to_property (_val[" properties" ]);
244
+ feature.geometry = simdjson_to_geometry (_val[" geometry" ]);
241
245
return feature;
242
246
}
243
247
244
- FeatureCollection simdjson_to_feature_collection (
248
+ simdjson_inline FeatureCollection simdjson_to_feature_collection (
245
249
simdjson::ondemand::object _val) {
246
250
FeatureCollection feature_collection;
247
- feature_collection.type = std::string (_val[" type" ]. get_string (). value () );
251
+ feature_collection.type = simdjson_to_string (_val[" type" ]);
248
252
for (auto val : _val[" features" ].get_array ()) {
249
253
feature_collection.features .push_back (simdjson_to_feature (val));
250
254
}
@@ -256,8 +260,8 @@ static rfl::Result<FeatureCollection> read_using_simdjson(
256
260
try {
257
261
simdjson::ondemand::parser parser;
258
262
auto padded_str = simdjson::padded_string (_json_string);
259
- auto doc = parser.iterate(padded_str). value () ;
260
- return simdjson_to_feature_collection (doc. get_object () );
263
+ auto doc = parser.iterate(padded_str);
264
+ return simdjson_to_feature_collection (doc);
261
265
} catch (std::exception &e) {
262
266
return rfl::Error (e.what ());
263
267
}
0 commit comments