diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-08-10 11:27:25 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-08-13 12:39:44 -0700 |
commit | 58202eaf80bdfe1273396d2abe6b1fee8fed937a (patch) | |
tree | 87000da34c0c7af322feb74db3e7752c49ce8e1f /src/mbgl/style/layers/background_layer.cpp | |
parent | b2f60a4bf2fb95c107bb94543ba6345779970e98 (diff) | |
download | qtlocation-mapboxgl-58202eaf80bdfe1273396d2abe6b1fee8fed937a.tar.gz |
[core] Optimize generated set{Paint,Layout}Property code
Diffstat (limited to 'src/mbgl/style/layers/background_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/background_layer.cpp | 124 |
1 files changed, 92 insertions, 32 deletions
diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 837d557722..88e175cb7c 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -158,70 +159,115 @@ TransitionOptions BackgroundLayer::getBackgroundOpacityTransition() const { using namespace conversion; optional<Error> BackgroundLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + BackgroundColor, + BackgroundPattern, + BackgroundOpacity, + BackgroundColorTransition, + BackgroundPatternTransition, + BackgroundOpacityTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("background-color"): + if (name == "background-color") { + property = Property::BackgroundColor; + } + break; + case util::hashFNV1a("background-color-transition"): + if (name == "background-color-transition") { + property = Property::BackgroundColorTransition; + } + break; + case util::hashFNV1a("background-pattern"): + if (name == "background-pattern") { + property = Property::BackgroundPattern; + } + break; + case util::hashFNV1a("background-pattern-transition"): + if (name == "background-pattern-transition") { + property = Property::BackgroundPatternTransition; + } + break; + case util::hashFNV1a("background-opacity"): + if (name == "background-opacity") { + property = Property::BackgroundOpacity; + } + break; + case util::hashFNV1a("background-opacity-transition"): + if (name == "background-opacity-transition") { + property = Property::BackgroundOpacityTransition; + } + break; - if (name == "background-color") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::BackgroundColor) { Error error; optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundColor(*typedValue); return nullopt; - } - if (name == "background-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setBackgroundColorTransition(*transition); - return nullopt; + } - if (name == "background-pattern") { + if (property == Property::BackgroundPattern) { Error error; optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundPattern(*typedValue); return nullopt; - } - if (name == "background-pattern-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setBackgroundPatternTransition(*transition); - return nullopt; + } - if (name == "background-opacity") { + if (property == Property::BackgroundOpacity) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundOpacity(*typedValue); return nullopt; + } - if (name == "background-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } + + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; + } + + if (property == Property::BackgroundColorTransition) { + setBackgroundColorTransition(*transition); + return nullopt; + } + + if (property == Property::BackgroundPatternTransition) { + setBackgroundPatternTransition(*transition); + return nullopt; + } + + if (property == Property::BackgroundOpacityTransition) { setBackgroundOpacityTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -242,7 +288,21 @@ optional<Error> BackgroundLayer::setLayoutProperty(const std::string& name, cons return nullopt; } + enum class Property { + Unknown, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + return Error { "layer doesn't support this property" }; } |