mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25: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>
20 lines
1.1 KiB
C++
20 lines
1.1 KiB
C++
#define GEOM_POINT 0 /* array of positions */
|
|
#define GEOM_MULTIPOINT 1 /* array of arrays of positions */
|
|
#define GEOM_LINESTRING 2 /* array of arrays of positions */
|
|
#define GEOM_MULTILINESTRING 3 /* array of arrays of arrays of positions */
|
|
#define GEOM_POLYGON 4 /* array of arrays of arrays of positions */
|
|
#define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */
|
|
#define GEOM_TYPES 6
|
|
|
|
extern const char *geometry_names[GEOM_TYPES];
|
|
extern int geometry_within[GEOM_TYPES];
|
|
extern int mb_geometry[GEOM_TYPES];
|
|
|
|
void json_context(json_object *j);
|
|
void parse_coordinates(int t, json_object *j, drawvec &out, int op, const char *fname, int line, json_object *feature);
|
|
std::pair<int, drawvec> parse_geometry(json_object *geometry, json_pull_ptr &jp, json_object *j,
|
|
int z, int x, int y, long long extent, bool fix_longitudes, bool mvt_style);
|
|
std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int extent, bool fix_longitudes);
|
|
|
|
serial_val stringify_value(json_object *value, const char *reading, int line, json_object *feature);
|