diff --git a/geojson.cpp b/geojson.cpp index 16ef9457..609e45cb 100644 --- a/geojson.cpp +++ b/geojson.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -41,7 +40,7 @@ #include "milo/dtoa_milo.h" #include "errors.hpp" -int serialize_geojson_feature(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, int layer, json_object *tippecanoe, json_object *feature, std::string layername) { +int serialize_geojson_feature(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, int layer, json_object *tippecanoe, json_object *feature, std::string const &layername) { json_object *geometry_type = json_hash_get(geometry, "type"); if (geometry_type == NULL) { static int warned = 0; @@ -182,36 +181,21 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom nprop = properties->value.object.length; } - std::vector metakey; - metakey.resize(nprop); + std::vector keys; + std::vector values; - std::vector metaval; - metaval.resize(nprop); - - std::vector metatype; - metatype.resize(nprop); - - size_t m = 0; + keys.reserve(nprop); + values.reserve(nprop); for (size_t i = 0; i < nprop; i++) { if (properties->value.object.keys[i]->type == JSON_STRING) { - std::string s(properties->value.object.keys[i]->value.string.string); - int type = -1; + std::string val; stringify_value(properties->value.object.values[i], type, val, sst->fname, sst->line, feature); - if (type >= 0) { - metakey[m] = properties->value.object.keys[i]->value.string.string; - metatype[m] = type; - metaval[m] = val; - m++; - } else { - metakey[m] = properties->value.object.keys[i]->value.string.string; - metatype[m] = mvt_null; - metaval[m] = "null"; - m++; - } + keys.emplace_back(properties->value.object.keys[i]->value.string.string); + values.emplace_back(serial_val(type, val)); } } @@ -238,15 +222,8 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom sf.layername = layername; } - for (size_t i = 0; i < m; i++) { - sf.full_keys.push_back(metakey[i]); - - serial_val sv; - sv.type = metatype[i]; - sv.s = metaval[i]; - - sf.full_values.push_back(sv); - } + sf.full_keys = std::move(keys); + sf.full_values = std::move(values); return serialize_feature(sst, sf); } diff --git a/serial.cpp b/serial.cpp index a33ae976..fc68e013 100644 --- a/serial.cpp +++ b/serial.cpp @@ -730,7 +730,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { } if (sst->layermap->count(sf.layername) == 0) { - sst->layermap->insert(std::pair(sf.layername, layermap_entry(sst->layermap->size()))); + sst->layermap->emplace(sf.layername, layermap_entry(sst->layermap->size())); } auto ai = sst->layermap->find(sf.layername); diff --git a/serial.hpp b/serial.hpp index f4ad239f..2467767b 100644 --- a/serial.hpp +++ b/serial.hpp @@ -36,11 +36,19 @@ void deserialize_byte(char **f, signed char *n); // mvt_double, mvt_bool, or mvt_null). Note that all numeric values, // whether integer or floating point, use mvt_double here. struct serial_val { - int type = 0; - std::string s = ""; + int type; + std::string s; bool operator<(const serial_val &o) const; bool operator!=(const serial_val &o) const; + + serial_val() { + type = 0; + } + + serial_val(int t, const std::string &val) + : type(t), s(val) { + } }; struct serial_feature {