I noticed that layer_map<CoordinateType> decode_tile(std::string const& buffer) at
|
layer_map<CoordinateType> decode_tile(std::string const& buffer) |
|
{ |
|
layer_map<CoordinateType> m; |
|
vtzero::vector_tile tile(buffer); |
|
while (auto layer = tile.next_layer()) |
|
{ |
|
mapbox::feature::feature_collection<CoordinateType> fc; |
|
while (auto feature = layer.next_feature()) |
|
{ |
|
auto f = extract_feature<CoordinateType>(feature); |
|
if (!f.geometry.template is<mapbox::geometry::empty>()) |
|
{ |
|
fc.push_back(f); |
|
} |
|
} |
|
|
|
if (!fc.empty()) |
|
{ |
|
m.emplace(std::string(layer.name()), std::move(fc)); |
|
} |
|
} |
|
return m; |
|
} |
does not leverage pre-allocation optimizations. We should likely do:
diff --git a/include/mapbox/vector_tile.hpp b/include/mapbox/vector_tile.hpp
index c61640b..0e8c672 100644
--- a/include/mapbox/vector_tile.hpp
+++ b/include/mapbox/vector_tile.hpp
@@ -66,12 +66,13 @@ layer_map<CoordinateType> decode_tile(std::string const& buffer)
while (auto layer = tile.next_layer())
{
mapbox::feature::feature_collection<CoordinateType> fc;
+ fc.reserve(layer.num_features());
while (auto feature = layer.next_feature())
{
auto f = extract_feature<CoordinateType>(feature);
if (!f.geometry.template is<mapbox::geometry::empty>())
{
- fc.push_back(f);
+ fc.push_back(std::move(f));
}
}
/cc @flippmoke to review and apply if this looks good.
I noticed that
layer_map<CoordinateType> decode_tile(std::string const& buffer)atvector-tile/include/mapbox/vector_tile.hpp
Lines 62 to 84 in 95c240b
/cc @flippmoke to review and apply if this looks good.