diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index 507cc7b08..3816b929e 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include #include @@ -26,21 +28,22 @@ LineAtlas::~LineAtlas() { } LinePatternPos LineAtlas::getDashPosition(const std::vector &dasharray, bool round) { + size_t key = round ? std::numeric_limits::min() : std::numeric_limits::max(); + for (const float part : dasharray) { + boost::hash_combine(key, part); + } + + // Note: We're not handling hash collisions here. + std::lock_guard lock(mtx); - - std::ostringstream sskey; - - for (const float &part : dasharray) { - sskey << part << "-"; + 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; } - sskey << round; - std::string key = sskey.str(); - - if (positions.find(key) == positions.end()) { - positions[key] = addDash(dasharray, round); - } - - return positions[key]; } LinePatternPos LineAtlas::addDash(const std::vector &dasharray, bool round) { diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index 191dc0c4d..df60a2dec 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -33,7 +33,7 @@ private: std::atomic dirty; uint32_t texture = 0; int nextRow = 0; - std::map positions; + std::map positions; }; };