summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-04-01 16:13:37 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-04-01 16:13:37 +0200
commitcc97675ca1f7e4f3241188bb550fe72ce1949488 (patch)
tree972b95598282b72df2ca057f4b89c6325d30b355
parenta0cbe920d850659e28b891be75625c36ffc36b8d (diff)
parent268129b9c17cb9489b1e7024cb12c684b56f485f (diff)
downloadqtlocation-mapboxgl-cc97675ca1f7e4f3241188bb550fe72ce1949488.tar.gz
Merge pull request #1170 from mapbox/1170-no-stringstream-for-hashing
Remove usage of stringstream for line dash atlas
-rw-r--r--src/mbgl/geometry/line_atlas.cpp27
-rw-r--r--src/mbgl/geometry/line_atlas.hpp2
2 files changed, 16 insertions, 13 deletions
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index 507cc7b087..3816b929e8 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) {
diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp
index 191dc0c4d4..df60a2dec5 100644
--- a/src/mbgl/geometry/line_atlas.hpp
+++ b/src/mbgl/geometry/line_atlas.hpp
@@ -33,7 +33,7 @@ private:
std::atomic<bool> dirty;
uint32_t texture = 0;
int nextRow = 0;
- std::map<std::string, LinePatternPos> positions;
+ std::map<size_t, LinePatternPos> positions;
};
};