diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-04-01 12:24:53 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-04-01 12:24:53 +0200 |
commit | a0cbe920d850659e28b891be75625c36ffc36b8d (patch) | |
tree | 47d51d626e30af7ac7977211ce23d5e9b64b43a8 | |
parent | 3d9b441c8b07fb7d005d305fa648cbd06c6dc15e (diff) | |
parent | 2beb836a0719291cc84d3d4222be83c4d3c649b2 (diff) | |
download | qtlocation-mapboxgl-a0cbe920d850659e28b891be75625c36ffc36b8d.tar.gz |
Merge pull request #1164 from mapbox/1164-parsing-speed-regression
Fix tile parsing performance regression
-rw-r--r-- | src/mbgl/map/vector_tile.cpp | 48 | ||||
-rw-r--r-- | src/mbgl/map/vector_tile.hpp | 2 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/mbgl/map/vector_tile.cpp b/src/mbgl/map/vector_tile.cpp index dca2168a47..01d52a348a 100644 --- a/src/mbgl/map/vector_tile.cpp +++ b/src/mbgl/map/vector_tile.cpp @@ -35,26 +35,7 @@ VectorTileFeature::VectorTileFeature(pbf feature_pbf, const VectorTileLayer& lay if (feature_pbf.tag == 1) { // id id = feature_pbf.varint<uint64_t>(); } else if (feature_pbf.tag == 2) { // tags - // tags are packed varints. They should have an even length. - pbf tags = feature_pbf.message(); - while (tags) { - uint32_t tag_key = tags.varint(); - - if (layer.keys.size() <= tag_key) { - throw std::runtime_error("feature referenced out of range key"); - } - - if (!tags) { - throw std::runtime_error("uneven number of feature tag ids"); - } - - uint32_t tag_val = tags.varint(); - if (layer.values.size() <= tag_val) { - throw std::runtime_error("feature referenced out of range value"); - } - - properties.emplace(tag_key, tag_val); - } + tags_pbf = feature_pbf.message(); } else if (feature_pbf.tag == 3) { // type type = (FeatureType)feature_pbf.varint(); } else if (feature_pbf.tag == 4) { // geometry @@ -70,11 +51,30 @@ mapbox::util::optional<Value> VectorTileFeature::getValue(const std::string& key if (keyIter == layer.keys.end()) { return mapbox::util::optional<Value>(); } - auto propIter = properties.find(keyIter->second); - if (propIter == properties.end()) { - return mapbox::util::optional<Value>(); + + pbf tags = tags_pbf; + while (tags) { + uint32_t tag_key = tags.varint(); + + if (layer.keys.size() <= tag_key) { + throw std::runtime_error("feature referenced out of range key"); + } + + if (!tags) { + throw std::runtime_error("uneven number of feature tag ids"); + } + + uint32_t tag_val = tags.varint(); + if (layer.values.size() <= tag_val) { + throw std::runtime_error("feature referenced out of range value"); + } + + if (tag_key == keyIter->second) { + return layer.values[tag_val]; + } } - return layer.values[propIter->second]; + + return mapbox::util::optional<Value>(); } GeometryCollection VectorTileFeature::getGeometries() const { diff --git a/src/mbgl/map/vector_tile.hpp b/src/mbgl/map/vector_tile.hpp index 9a23c3b189..77a0b4ab16 100644 --- a/src/mbgl/map/vector_tile.hpp +++ b/src/mbgl/map/vector_tile.hpp @@ -22,7 +22,7 @@ private: const VectorTileLayer& layer; uint64_t id = 0; FeatureType type = FeatureType::Unknown; - std::unordered_map<uint32_t, uint32_t> properties; + pbf tags_pbf; pbf geometry_pbf; }; |