Skip to content

Commit bf531cf

Browse files
committed
core: do not use JSON serialization for layer grouping key
1 parent 685ae5f commit bf531cf

35 files changed

Lines changed: 43 additions & 104 deletions

include/mbgl/style/filter.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#include <mbgl/util/geometry.hpp>
66
#include <mbgl/style/expression/expression.hpp>
77

8-
#include <string>
9-
#include <vector>
10-
#include <tuple>
118
#include <optional>
129

1310
namespace mbgl {

src/mbgl/plugin/plugin_layer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ std::unique_ptr<Layer> PluginLayer::cloneRef(const std::string& id_) const {
3434
return std::make_unique<PluginLayer>(std::move(impl_));
3535
}
3636

37-
void PluginLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {}
38-
3937
Value PluginLayer::serialize() const {
4038
auto result = Layer::serialize();
4139
return result;

src/mbgl/plugin/plugin_layer_impl.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class PluginLayer::Impl : public Layer::Impl {
8787
using Layer::Impl::Impl;
8888

8989
bool hasLayoutDifference(const Layer::Impl&) const override;
90-
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
9190

9291
const LayerTypeInfo* getTypeInfo() const noexcept final { return &_layerTypeInfo; }
9392

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,46 @@
11
#include <mbgl/renderer/group_by_layout.hpp>
2-
#include <mbgl/style/conversion/stringify.hpp>
3-
#include <mbgl/util/rapidjson.hpp>
2+
#include <mbgl/util/instrumentation.hpp>
3+
#include <mbgl/util/containers.hpp>
4+
#include <mbgl/style/layer_properties.hpp>
45

5-
#include <rapidjson/writer.h>
6-
#include <rapidjson/stringbuffer.h>
7-
8-
#include <unordered_map>
6+
#include <string>
97

108
namespace mbgl {
119

12-
std::string layoutKey(const style::Layer::Impl& impl) {
10+
std::string createLayoutKey(const style::Layer::Impl& impl) {
1311
using namespace style::conversion;
12+
std::string key;
13+
key += std::to_string(reinterpret_cast<uint64_t>(impl.getTypeInfo()));
14+
key += impl.source;
15+
key += impl.sourceLayer;
16+
key += std::to_string(impl.maxZoom);
17+
key += std::to_string(impl.minZoom);
18+
key += std::to_string(static_cast<uint32_t>(impl.visibility));
19+
return key;
20+
}
1421

15-
rapidjson::StringBuffer s;
16-
rapidjson::Writer<rapidjson::StringBuffer> writer(s);
17-
18-
writer.StartArray();
19-
writer.Uint64(reinterpret_cast<uint64_t>(impl.getTypeInfo()));
20-
writer.String(impl.source);
21-
writer.String(impl.sourceLayer);
22-
writer.Double(impl.minZoom);
23-
writer.Double(impl.maxZoom);
24-
writer.Uint(static_cast<uint32_t>(impl.visibility));
25-
stringify(writer, impl.filter);
26-
impl.stringifyLayout(writer);
27-
writer.EndArray();
28-
29-
return s.GetString();
22+
GroupMap groupLayers(const std::vector<Immutable<style::LayerProperties>>& layers) {
23+
MLN_TRACE_FUNC();
24+
25+
mbgl::unordered_map<std::string, std::vector<Immutable<style::LayerProperties>>> groupMap;
26+
groupMap.reserve(layers.size());
27+
28+
for (auto layer : layers) {
29+
// this part of the key is unique per filter
30+
auto layoutFilterKey = 0;
31+
while (true) {
32+
auto layoutKey = createLayoutKey(*layer->baseImpl) + std::to_string(layoutFilterKey);
33+
if (groupMap.contains(layoutKey)) {
34+
if (groupMap[layoutKey].front()->baseImpl->filter != layer->baseImpl->filter) {
35+
++layoutFilterKey;
36+
continue;
37+
}
38+
}
39+
groupMap[layoutKey].push_back(std::move(layer));
40+
break;
41+
}
42+
}
43+
return groupMap;
3044
}
3145

3246
} // namespace mbgl
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#pragma once
22

33
#include <mbgl/style/layer_impl.hpp>
4+
#include <mbgl/util/containers.hpp>
5+
#include <mbgl/style/layer_properties.hpp>
46

57
#include <vector>
6-
#include <memory>
78

89
namespace mbgl {
910

10-
std::string layoutKey(const style::Layer::Impl& impl);
11+
using GroupMap = mbgl::unordered_map<std::string, std::vector<Immutable<style::LayerProperties>>>;
12+
13+
GroupMap groupLayers(const std::vector<Immutable<style::LayerProperties>> &);
1114

1215
} // namespace mbgl

src/mbgl/renderer/sources/render_tile_source.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class PolylineLayerImpl : public Layer::Impl {
4949
PolylineLayerImpl()
5050
: Layer::Impl("", "") {}
5151
bool hasLayoutDifference(const Layer::Impl&) const override { return false; }
52-
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override {}
5352

5453
const LayerTypeInfo* getTypeInfo() const noexcept final { return staticTypeInfo(); }
5554
static const LayerTypeInfo* staticTypeInfo() noexcept {

src/mbgl/style/layer_impl.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class Layer::Impl {
3939
// filter, visibility, layout properties, or data-driven paint properties.
4040
virtual bool hasLayoutDifference(const Layer::Impl&) const = 0;
4141

42-
// Utility function for automatic layer grouping.
43-
virtual void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const = 0;
44-
4542
// Returns pointer to the statically allocated layer type info structure.
4643
virtual const LayerTypeInfo* getTypeInfo() const noexcept = 0;
4744

src/mbgl/style/layers/background_layer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ std::unique_ptr<Layer> BackgroundLayer::cloneRef(const std::string& id_) const {
5858
return std::make_unique<BackgroundLayer>(std::move(impl_));
5959
}
6060

61-
void BackgroundLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
62-
}
63-
6461
// Layout properties
6562

6663

src/mbgl/style/layers/background_layer_impl.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class BackgroundLayer::Impl : public Layer::Impl {
2929
Impl(const Impl&);
3030

3131
bool hasLayoutDifference(const Layer::Impl&) const override;
32-
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
3332

3433
public:
3534
BackgroundPaintProperties::Transitionable paint;

src/mbgl/style/layers/circle_layer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ std::unique_ptr<Layer> CircleLayer::cloneRef(const std::string& id_) const {
5858
return std::make_unique<CircleLayer>(std::move(impl_));
5959
}
6060

61-
void CircleLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
62-
layout.stringify(writer);
63-
}
64-
6561
// Layout properties
6662

6763
PropertyValue<float> CircleLayer::getDefaultCircleSortKey() {

0 commit comments

Comments
 (0)