Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x branch optimization #32

Open
springmeyer opened this issue Dec 14, 2017 · 0 comments
Open

2.x branch optimization #32

springmeyer opened this issue Dec 14, 2017 · 0 comments
Assignees
Labels
Milestone

Comments

@springmeyer
Copy link
Contributor

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.

@flippmoke flippmoke self-assigned this Jan 17, 2018
@flippmoke flippmoke added the 2.x label Feb 2, 2018
@flippmoke flippmoke added this to the 2.0 milestone Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants