diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-10-22 15:14:21 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-10-22 15:14:21 +0200 |
commit | 905c4294be495d15591885a2438ca0b8abc8decf (patch) | |
tree | 851a94849eb7a1f3269b91de6054846cfbda722b /src/style | |
parent | c6e4cf2f80216c7139b6587dcd6d919080aef20d (diff) | |
parent | 8954b3971f5cb90dc4b18e61b58ea6e41c54fffe (diff) | |
download | qtlocation-mapboxgl-905c4294be495d15591885a2438ca0b8abc8decf.tar.gz |
Merge branch 'libuv-0.10-headless-display' into mason
Conflicts:
common/http_request_baton_curl.cpp
include/mbgl/map/map.hpp
include/mbgl/util/uv_detail.hpp
scripts/travis_before_install.sh
setup-libraries.sh
src/map/map.cpp
src/storage/file_request_baton.cpp
src/storage/http_request.cpp
src/util/uv-messenger.c
Diffstat (limited to 'src/style')
-rw-r--r-- | src/style/class_dictionary.cpp | 34 | ||||
-rw-r--r-- | src/style/style_layer.cpp | 2 | ||||
-rw-r--r-- | src/style/style_parser.cpp | 2 |
3 files changed, 30 insertions, 8 deletions
diff --git a/src/style/class_dictionary.cpp b/src/style/class_dictionary.cpp index 6e1eb5a879..ba7c0d55be 100644 --- a/src/style/class_dictionary.cpp +++ b/src/style/class_dictionary.cpp @@ -1,8 +1,34 @@ #include <mbgl/style/class_dictionary.hpp> +#include <uv.h> + namespace mbgl { -ClassID ClassDictionary::Lookup(const std::string &class_name) { +ClassDictionary::ClassDictionary() {} + +ClassDictionary &ClassDictionary::Get() { + // Note: We should eventually switch to uv_key_* functions, but libuv 0.10 doesn't have these + // yet. Instead, we're using the pthread functions directly for now. + static pthread_once_t store_once = PTHREAD_ONCE_INIT; + static pthread_key_t store_key; + + // Create the key. + pthread_once(&store_once, []() { + pthread_key_create(&store_key, [](void *ptr) { + delete reinterpret_cast<ClassDictionary *>(ptr); + }); + }); + + ClassDictionary *ptr = reinterpret_cast<ClassDictionary *>(pthread_getspecific(store_key)); + if (ptr == nullptr) { + ptr = new ClassDictionary(); + pthread_setspecific(store_key, ptr); + } + + return *ptr; +} + +ClassID ClassDictionary::lookup(const std::string &class_name) { auto it = store.find(class_name); if (it == store.end()) { // Insert the class name into the store. @@ -14,7 +40,7 @@ ClassID ClassDictionary::Lookup(const std::string &class_name) { } } -ClassID ClassDictionary::Normalize(ClassID id) { +ClassID ClassDictionary::normalize(ClassID id) { if (id >= ClassID::Named) { return ClassID::Named; } else { @@ -22,8 +48,4 @@ ClassID ClassDictionary::Normalize(ClassID id) { } } - -std::unordered_map<std::string, ClassID> ClassDictionary::store = { { "", ClassID::Default } }; -uint32_t ClassDictionary::offset = 0; - } diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index 4f758fe723..b1b878cc8d 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -23,7 +23,7 @@ void StyleLayer::setClasses(const std::vector<std::string> &class_names, const t for (auto it = class_names.rbegin(); it != class_names.rend(); it++) { const std::string &class_name = *it; // From here on, we're only dealing with IDs to avoid comparing strings all the time. - const ClassID class_id = ClassDictionary::Lookup(class_name); + const ClassID class_id = ClassDictionary::Get().lookup(class_name); applyClassProperties(class_id, already_applied, now, defaultTransition); } diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index c2247d51b2..2a64ab38f8 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -554,7 +554,7 @@ void StyleParser::parseStyles(JSVal value, std::map<ClassID, ClassProperties> &s if (name == "style") { parseStyle(replaceConstant(itr->value), styles[ClassID::Default]); } else if (name.compare(0, 6, "style.") == 0 && name.length() > 6) { - const ClassID class_id = ClassDictionary::Lookup(name.substr(6)); + const ClassID class_id = ClassDictionary::Get().lookup(name.substr(6)); parseStyle(replaceConstant(itr->value), styles[class_id]); } } |