2.x branch optimization

Open
#32 0 comments 0 reactions 1 assignee View on GitHub

@flippmoke is already working on this.

Since Jan 17, 2018.

Assessment

This issue has not been assessed yet.

Description

2.x

I noticed that layer_map<CoordinateType> decode_tile(std::string const& buffer) at https://github.com/mapbox/vector-tile/blob/95c240bd8c8373bc0c06966a62565c5d73fdef73/include/mapbox/vector_tile.hpp#L62-L84 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.

Dominant language
C++
Stars
52
Forks
33
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mapbox/vector-tile

All issues in mapbox/vector-tile

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.