[core] Avoid copying feature properties
This commit is contained in:
@@ -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; };
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
return apply_visitor(ToFeatureType(), feature.geometry);
|
||||
}
|
||||
|
||||
PropertyMap getProperties() const override {
|
||||
const PropertyMap& getProperties() const override {
|
||||
return feature.properties;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user