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

Commit

Permalink
wip: binary size
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Feb 25, 2020
1 parent 631aac4 commit b879b26
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 210 deletions.
1 change: 1 addition & 0 deletions include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class Layer {

protected:
virtual Mutable<Impl> mutableBaseImpl() const = 0;
void serializeProperty(Value&, const StyleProperty&, const char* propertyName, uint8_t propertyId, uint8_t paintPropertyCount) const;

LayerObserver* observer;
mapbox::base::WeakPtrFactory<Layer> weakFactory {this};
Expand Down
16 changes: 16 additions & 0 deletions src/mbgl/style/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,25 @@ Value Layer::serialize() const {
result.emplace("maxzoom", getMaxZoom());
}

if (getVisibility() == VisibilityType::None) {
result["layout"] = mapbox::base::ValueObject{{"visibility", "none"}};
}

return result;
}

void Layer::serializeProperty(Value& out, const StyleProperty& property, const char* propertyName, uint8_t propertyId, uint8_t paintPropertyCount) const {
assert(out.getObject());
auto& object = *(out.getObject());
std::string propertyType = propertyId < paintPropertyCount ? "paint" : "layout";
if (object.count(propertyType)) {
assert(object[propertyType].getObject());
object[propertyType].getObject()->emplace(propertyName, property.getValue());
} else {
object[propertyType] = mapbox::base::ValueObject{{propertyName, property.getValue()}};
}
}

void Layer::setObserver(LayerObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/background_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,30 +202,11 @@ StyleProperty getLayerProperty(const BackgroundLayer& layer, const std::string&

Value BackgroundLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,30 +482,11 @@ StyleProperty getLayerProperty(const CircleLayer& layer, const std::string& name

Value CircleLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/fill_extrusion_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,30 +377,11 @@ StyleProperty getLayerProperty(const FillExtrusionLayer& layer, const std::strin

Value FillExtrusionLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/fill_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,30 +362,11 @@ StyleProperty getLayerProperty(const FillLayer& layer, const std::string& name)

Value FillLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/heatmap_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,30 +274,11 @@ StyleProperty getLayerProperty(const HeatmapLayer& layer, const std::string& nam

Value HeatmapLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/hillshade_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,30 +307,11 @@ StyleProperty getLayerProperty(const HillshadeLayer& layer, const std::string& n

Value HillshadeLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/layer.cpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -262,30 +262,11 @@ StyleProperty getLayerProperty(const <%- camelize(type) -%>Layer& layer, const s
Value <%- camelize(type) %>Layer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}
if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}
if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}
if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/line_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,30 +579,11 @@ StyleProperty getLayerProperty(const LineLayer& layer, const std::string& name)

Value LineLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/raster_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,30 +377,11 @@ StyleProperty getLayerProperty(const RasterLayer& layer, const std::string& name

Value RasterLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down
23 changes: 2 additions & 21 deletions src/mbgl/style/layers/symbol_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,30 +1367,11 @@ StyleProperty getLayerProperty(const SymbolLayer& layer, const std::string& name

Value SymbolLayer::serialize() const {
auto result = Layer::serialize();
auto* object = result.getObject();
assert(object);
mapbox::base::ValueObject paintProperties;
mapbox::base::ValueObject layoutProperties;
assert(result.getObject());
for (const auto& property : layerProperties) {
auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
if (property.second < PaintPropertyCount) {
paintProperties.emplace(property.first.c_str(), styleProperty.getValue());
} else {
layoutProperties.emplace(property.first.c_str(), styleProperty.getValue());
}
}

if (getVisibility() == VisibilityType::None) {
layoutProperties.emplace("visibility", "none");
}

if (!paintProperties.empty()) {
object->emplace("paint", std::move(paintProperties));
}

if (!layoutProperties.empty()) {
object->emplace("layout", std::move(layoutProperties));
serializeProperty(result, styleProperty, property.first.c_str(), property.second, PaintPropertyCount);
}
return result;
}
Expand Down

0 comments on commit b879b26

Please sign in to comment.