[core] Prepare Filter and FilterEvaluator for extraction (#5366)

This commit is contained in:
John Firebaugh
2016-06-15 14:55:45 -07:00
committed by GitHub
parent 199ea2a82a
commit a0b2982119
8 changed files with 74 additions and 98 deletions

View File

@@ -13,32 +13,6 @@ using namespace mbgl;
typedef std::multimap<std::string, Value> Properties;
class StubFeature : public GeometryTileFeature {
public:
inline StubFeature(const Properties& properties_, FeatureType type_)
: properties(properties_), type(type_) {
}
optional<Value> getValue(const std::string& key) const override {
auto it = properties.find(key);
if (it == properties.end())
return optional<Value>();
return it->second;
}
FeatureType getType() const override {
return type;
}
GeometryCollection getGeometries() const override {
return GeometryCollection();
}
private:
const Properties properties;
FeatureType type;
};
style::Filter parse(const char* expression) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
doc.Parse<0>(expression);
@@ -54,10 +28,14 @@ static void Parse_Filter(benchmark::State& state) {
static void Parse_EvaluateFilter(benchmark::State& state) {
const style::Filter filter = parse(R"FILTER(["==", "foo", "bar"])FILTER");
const Properties properties = { { "foo", std::string("bar") } };
const StubFeature feature(properties, FeatureType::Unknown);
while (state.KeepRunning()) {
style::Filter::visit(filter, style::FilterEvaluator{ feature });
filter(FeatureType::Unknown, [&] (const std::string& key) -> optional<Value> {
auto it = properties.find(key);
if (it == properties.end())
return {};
return it->second;
});
}
}