mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-03 08:55:41 +02:00
Migrate jsonpull to unique_ptr ownership
Replaces the shared_ptr-based json_object_ptr with a unique_ptr that has a stateless custom deleter dispatching on json_object::type before calling the right subclass destructor. Eliminates per-node atomic reference-counting and the control-block allocation that shared_ptr required for every node in the tree. API now distinguishes owning and borrowing pointers explicitly: - json_read / json_read_separators / json_hash_get return raw json_object * (borrowed from the parser-owned tree). - json_read_tree / json_disconnect return json_object_ptr (caller takes ownership; back-pointers are cleared so the subtree can outlive the parser). - json_free / json_context / json_stringify take raw pointers. - The parser's container_stack holds raw pointers; jp->root keeps unique_ptr ownership of the most recent top-level value. Internally, take_from_owner moves the unique_ptr out of whichever parent vector / hash entry / parser root owned it, which both json_free and json_disconnect rely on. In the streaming parsers (parse_feature, parse_layers, the geojson-loop callback), we are careful to free `j` only after we have processed a complete Feature: json_read returns each token as the tree is being built up, and freeing an intermediate node would splice it out of the surrounding hash and corrupt the in-progress feature. Benchmark (tl_2022_us_county.json, -z0 --extend-zooms-if-still-dropping, median of 5 runs on macOS arm64): 8.5s, vs 10.6s with shared_ptr and 8.7s on the pre-refactor C baseline. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+3
-3
@@ -398,17 +398,17 @@ void readFeature(protozero::pbf_reader &pbf, size_t dim, double e, std::vector<s
|
||||
json_object_ptr o = json_read_tree(jp);
|
||||
|
||||
if (o != nullptr) {
|
||||
json_object_ptr min = json_hash_get(o, "minzoom");
|
||||
json_object *min = json_hash_get(o, "minzoom");
|
||||
if (min != nullptr && (min->type == JSON_NUMBER)) {
|
||||
sf.tippecanoe_minzoom = integer_zoom(sst->fname, milo::dtoa_milo(min->number()));
|
||||
}
|
||||
|
||||
json_object_ptr max = json_hash_get(o, "maxzoom");
|
||||
json_object *max = json_hash_get(o, "maxzoom");
|
||||
if (max != nullptr && (max->type == JSON_NUMBER)) {
|
||||
sf.tippecanoe_maxzoom = integer_zoom(sst->fname, milo::dtoa_milo(max->number()));
|
||||
}
|
||||
|
||||
json_object_ptr tlayer = json_hash_get(o, "layer");
|
||||
json_object *tlayer = json_hash_get(o, "layer");
|
||||
if (tlayer != nullptr && (tlayer->type == JSON_STRING)) {
|
||||
layername = tlayer->string();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user