Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Avoid copying feature properties
Browse files Browse the repository at this point in the history
  • Loading branch information
pozdnyakov committed Jul 25, 2019
1 parent e6e1e15 commit 273ad43
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/mbgl/layout/symbol_feature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SymbolFeature : public GeometryTileFeature {

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; };

Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/style/expression/compound_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/expression/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GeoJSONFeature : public GeometryTileFeature {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/tile/geojson_tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GeoJSONTileFeature : public GeometryTileFeature {
return apply_visitor(ToFeatureType(), feature.geometry);
}

PropertyMap getProperties() const override {
const PropertyMap& getProperties() const override {
return feature.properties;
}

Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/tile/geometry_tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/tile/geometry_tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GeometryTileFeature {
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;
};
Expand Down
7 changes: 5 additions & 2 deletions src/mbgl/tile/vector_tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/tile/vector_tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ class VectorTileFeature : public GeometryTileFeature {

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 {
Expand Down
2 changes: 1 addition & 1 deletion test/tile/vector_tile.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down

0 comments on commit 273ad43

Please sign in to comment.