mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 16:35:40 +02:00
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>
31 lines
719 B
C++
31 lines
719 B
C++
#ifndef GEOJSON_HPP
|
|
#define GEOJSON_HPP
|
|
|
|
#include <stdio.h>
|
|
#include <set>
|
|
#include <map>
|
|
#include <string>
|
|
#include "mbtiles.hpp"
|
|
#include "jsonpull/jsonpull.h"
|
|
#include "serial.hpp"
|
|
|
|
struct parse_json_args {
|
|
json_pull_ptr jp;
|
|
int layer;
|
|
std::string *layername;
|
|
|
|
struct serialization_state *sst;
|
|
|
|
parse_json_args(json_pull_ptr jp1, int layer1, std::string *layername1, struct serialization_state *sst1)
|
|
: jp(jp1), layer(layer1), layername(layername1), sst(sst1) {
|
|
}
|
|
};
|
|
|
|
json_pull_ptr json_begin_map(char *map, long long len);
|
|
void json_end_map(json_pull_ptr &jp);
|
|
|
|
void parse_json(struct serialization_state *sst, json_pull_ptr &jp, int layer, std::string layername);
|
|
void *run_parse_json(void *v);
|
|
|
|
#endif
|