diff options
Diffstat (limited to 'src/mbgl/geometry/line_atlas.cpp')
-rw-r--r-- | src/mbgl/geometry/line_atlas.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index 507cc7b087..f64989d661 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -4,6 +4,8 @@ #include <mbgl/platform/log.hpp> #include <mbgl/platform/platform.hpp> +#include <boost/functional/hash.hpp> + #include <sstream> #include <cmath> @@ -26,21 +28,22 @@ LineAtlas::~LineAtlas() { } LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, bool round) { - std::lock_guard<std::recursive_mutex> lock(mtx); - - std::ostringstream sskey; - - for (const float &part : dasharray) { - sskey << part << "-"; + size_t key = round ? std::numeric_limits<size_t>::min() : std::numeric_limits<size_t>::max(); + for (const float part : dasharray) { + boost::hash_combine<float>(key, part); } - sskey << round; - std::string key = sskey.str(); - if (positions.find(key) == positions.end()) { - positions[key] = addDash(dasharray, round); - } + // Note: We're not handling hash collisions here. - return positions[key]; + std::lock_guard<std::recursive_mutex> lock(mtx); + const auto it = positions.find(key); + if (it == positions.end()) { + auto inserted = positions.emplace(key, addDash(dasharray, round)); + assert(inserted.second); + return inserted.first->second; + } else { + return it->second; + } } LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool round) { @@ -55,7 +58,7 @@ LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool roun } float length = 0; - for (const float &part : dasharray) { + for (const float part : dasharray) { length += part; } |