summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-24 18:19:00 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-25 11:43:37 +0300
commit54e3a05d522445307b493937081b5a32cae09361 (patch)
tree48d822d20a89743ea93dd0fd15a5878b9609d8b4
parent7ce892366d89964a04361201db66bced4dc01dee (diff)
downloadqtlocation-mapboxgl-upstream/mikhail_avoid_feature_properties_copying.tar.gz
[core] Avoid copying feature propertiesupstream/mikhail_avoid_feature_properties_copying
-rw-r--r--src/mbgl/layout/symbol_feature.hpp2
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp3
-rw-r--r--src/mbgl/style/expression/expression.cpp2
-rw-r--r--src/mbgl/tile/geojson_tile_data.hpp2
-rw-r--r--src/mbgl/tile/geometry_tile_data.cpp5
-rw-r--r--src/mbgl/tile/geometry_tile_data.hpp2
-rw-r--r--src/mbgl/tile/vector_tile_data.cpp7
-rw-r--r--src/mbgl/tile/vector_tile_data.hpp3
-rw-r--r--test/tile/vector_tile.test.cpp2
9 files changed, 19 insertions, 9 deletions
diff --git a/src/mbgl/layout/symbol_feature.hpp b/src/mbgl/layout/symbol_feature.hpp
index 72e88fb55e..ed9c0783d0 100644
--- a/src/mbgl/layout/symbol_feature.hpp
+++ b/src/mbgl/layout/symbol_feature.hpp
@@ -18,7 +18,7 @@ public:
FeatureType getType() const override { return feature->getType(); }
optional<Value> getValue(const std::string& key) const override { return feature->getValue(key); };
- std::unordered_map<std::string,Value> getProperties() const override { return feature->getProperties(); };
+ const PropertyMap& getProperties() const override { return feature->getProperties(); };
FeatureIdentifier getID() const override { return feature->getID(); };
const GeometryCollection& getGeometries() const override { return geometry; };
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp
index cc1d58025b..34f0f5dea3 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -423,7 +423,8 @@ const auto& propertiesCompoundExpression() {
};
}
std::unordered_map<std::string, Value> result;
- const PropertyMap properties = params.feature->getProperties();
+ const PropertyMap& properties = params.feature->getProperties();
+ result.reserve(properties.size());
for (const auto& entry : properties) {
result[entry.first] = toExpressionValue(entry.second);
}
diff --git a/src/mbgl/style/expression/expression.cpp b/src/mbgl/style/expression/expression.cpp
index 4c810431d0..d61f435eec 100644
--- a/src/mbgl/style/expression/expression.cpp
+++ b/src/mbgl/style/expression/expression.cpp
@@ -15,7 +15,7 @@ public:
FeatureType getType() const override {
return apply_visitor(ToFeatureType(), feature.geometry);
}
- PropertyMap getProperties() const override { return feature.properties; }
+ const PropertyMap& getProperties() const override { return feature.properties; }
FeatureIdentifier getID() const override { return feature.id; }
optional<mbgl::Value> getValue(const std::string& key) const override {
auto it = feature.properties.find(key);
diff --git a/src/mbgl/tile/geojson_tile_data.hpp b/src/mbgl/tile/geojson_tile_data.hpp
index 21a65144d9..5559965cd7 100644
--- a/src/mbgl/tile/geojson_tile_data.hpp
+++ b/src/mbgl/tile/geojson_tile_data.hpp
@@ -17,7 +17,7 @@ public:
return apply_visitor(ToFeatureType(), feature.geometry);
}
- PropertyMap getProperties() const override {
+ const PropertyMap& getProperties() const override {
return feature.properties;
}
diff --git a/src/mbgl/tile/geometry_tile_data.cpp b/src/mbgl/tile/geometry_tile_data.cpp
index db9f37ad4b..5320df6893 100644
--- a/src/mbgl/tile/geometry_tile_data.cpp
+++ b/src/mbgl/tile/geometry_tile_data.cpp
@@ -179,6 +179,11 @@ Feature convertFeature(const GeometryTileFeature& geometryTileFeature, const Can
return feature;
}
+const PropertyMap& GeometryTileFeature::getProperties() const {
+ static const PropertyMap dummy;
+ return dummy;
+}
+
const GeometryCollection& GeometryTileFeature::getGeometries() const {
static const GeometryCollection dummy;
return dummy;
diff --git a/src/mbgl/tile/geometry_tile_data.hpp b/src/mbgl/tile/geometry_tile_data.hpp
index a06e2be835..5d43a68388 100644
--- a/src/mbgl/tile/geometry_tile_data.hpp
+++ b/src/mbgl/tile/geometry_tile_data.hpp
@@ -49,7 +49,7 @@ public:
virtual ~GeometryTileFeature() = default;
virtual FeatureType getType() const = 0;
virtual optional<Value> getValue(const std::string& key) const = 0;
- virtual PropertyMap getProperties() const { return PropertyMap(); }
+ virtual const PropertyMap& getProperties() const;
virtual FeatureIdentifier getID() const { return NullValue {}; }
virtual const GeometryCollection& getGeometries() const;
};
diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp
index 926e596080..d53f1deba6 100644
--- a/src/mbgl/tile/vector_tile_data.cpp
+++ b/src/mbgl/tile/vector_tile_data.cpp
@@ -26,8 +26,11 @@ optional<Value> VectorTileFeature::getValue(const std::string& key) const {
return value->is<NullValue>() ? nullopt : std::move(value);
}
-std::unordered_map<std::string, Value> VectorTileFeature::getProperties() const {
- return feature.getProperties();
+const PropertyMap& VectorTileFeature::getProperties() const {
+ if (!properties) {
+ properties = feature.getProperties();
+ }
+ return *properties;
}
FeatureIdentifier VectorTileFeature::getID() const {
diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp
index 525c7935e4..f5086936f8 100644
--- a/src/mbgl/tile/vector_tile_data.hpp
+++ b/src/mbgl/tile/vector_tile_data.hpp
@@ -15,13 +15,14 @@ public:
FeatureType getType() const override;
optional<Value> getValue(const std::string& key) const override;
- std::unordered_map<std::string, Value> getProperties() const override;
+ const PropertyMap& getProperties() const override;
FeatureIdentifier getID() const override;
const GeometryCollection& getGeometries() const override;
private:
mapbox::vector_tile::feature feature;
mutable optional<GeometryCollection> lines;
+ mutable optional<PropertyMap> properties;
};
class VectorTileLayer : public GeometryTileLayer {
diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp
index b912af1f15..940c0272db 100644
--- a/test/tile/vector_tile.test.cpp
+++ b/test/tile/vector_tile.test.cpp
@@ -98,7 +98,7 @@ TEST(VectorTileData, ParseResults) {
ASSERT_TRUE(feature->getID().is<uint64_t>());
ASSERT_EQ(feature->getID().get<uint64_t>(), 1u);
- std::unordered_map<std::string, Value> properties = feature->getProperties();
+ const std::unordered_map<std::string, Value>& properties = feature->getProperties();
ASSERT_EQ(properties.size(), 3u);
ASSERT_EQ(properties.at("disputed"), *feature->getValue("disputed"));