summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-10-18 17:57:04 +0200
committerKonstantin Käfer <mail@kkaefer.com>2018-10-23 12:23:40 +0200
commit70d5972e104aac91f4198540d4af14562e92d555 (patch)
tree83e92385784d2c89df052690cd3a15ad1ca3eb01
parent282c71e8e9a8ec9c2eab612f2e60a71b15d24c8a (diff)
downloadqtlocation-mapboxgl-70d5972e104aac91f4198540d4af14562e92d555.tar.gz
[core] don't use <boost/functional/hash.hpp> to avoid <locale> include
-rw-r--r--cmake/core-files.txt1
-rw-r--r--src/mbgl/geometry/line_atlas.cpp5
-rw-r--r--src/mbgl/layout/merge_lines.cpp8
-rw-r--r--src/mbgl/text/glyph.hpp4
-rw-r--r--src/mbgl/text/glyph_manager.cpp2
-rw-r--r--src/mbgl/text/glyph_range.hpp21
-rw-r--r--src/mbgl/tile/tile_id_hash.cpp17
-rw-r--r--src/mbgl/util/font_stack.cpp8
-rw-r--r--src/mbgl/util/hash.hpp23
9 files changed, 57 insertions, 32 deletions
diff --git a/cmake/core-files.txt b/cmake/core-files.txt
index 7c52e08ccf..9e83ceb66c 100644
--- a/cmake/core-files.txt
+++ b/cmake/core-files.txt
@@ -726,6 +726,7 @@ src/mbgl/util/geo.cpp
src/mbgl/util/geojson_impl.cpp
src/mbgl/util/grid_index.cpp
src/mbgl/util/grid_index.hpp
+src/mbgl/util/hash.hpp
src/mbgl/util/http_header.cpp
src/mbgl/util/http_header.hpp
src/mbgl/util/http_timeout.cpp
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index 1129bd0b20..ba14655cab 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -2,8 +2,7 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
-
-#include <boost/functional/hash.hpp>
+#include <mbgl/util/hash.hpp>
#include <sstream>
#include <cmath>
@@ -22,7 +21,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector<float>& dasharray,
size_t key = patternCap == LinePatternCap::Round ? std::numeric_limits<size_t>::min()
: std::numeric_limits<size_t>::max();
for (const float part : dasharray) {
- boost::hash_combine<float>(key, part);
+ util::hash_combine<float>(key, part);
}
// Note: We're not handling hash collisions here.
diff --git a/src/mbgl/layout/merge_lines.cpp b/src/mbgl/layout/merge_lines.cpp
index 2a3afa42b2..616a8a3ff5 100644
--- a/src/mbgl/layout/merge_lines.cpp
+++ b/src/mbgl/layout/merge_lines.cpp
@@ -1,7 +1,6 @@
#include <mbgl/layout/merge_lines.hpp>
#include <mbgl/layout/symbol_feature.hpp>
-
-#include <boost/functional/hash.hpp>
+#include <mbgl/util/hash.hpp>
namespace mbgl {
namespace util {
@@ -43,10 +42,7 @@ size_t mergeFromLeft(std::vector<SymbolFeature>& features,
}
size_t getKey(const std::u16string& text, const GeometryCoordinate& coord) {
- auto hash = std::hash<std::u16string>()(text);
- boost::hash_combine(hash, coord.x);
- boost::hash_combine(hash, coord.y);
- return hash;
+ return util::hash(text, coord.x, coord.y);
}
void mergeLines(std::vector<SymbolFeature>& features) {
diff --git a/src/mbgl/text/glyph.hpp b/src/mbgl/text/glyph.hpp
index 55cd50fd9b..034784dc24 100644
--- a/src/mbgl/text/glyph.hpp
+++ b/src/mbgl/text/glyph.hpp
@@ -115,7 +115,7 @@ MBGL_CONSTEXPR WritingModeType operator~(WritingModeType value) {
return WritingModeType(~mbgl::underlying_type(value));
}
-using GlyphDependencies = std::map<FontStack,GlyphIDs>;
-using GlyphRangeDependencies = std::map<FontStack,GlyphRangeSet>;
+using GlyphDependencies = std::map<FontStack, GlyphIDs>;
+using GlyphRangeDependencies = std::map<FontStack, std::unordered_set<GlyphRange>>;
} // end namespace mbgl
diff --git a/src/mbgl/text/glyph_manager.cpp b/src/mbgl/text/glyph_manager.cpp
index c4a7a2de66..b947ef72c8 100644
--- a/src/mbgl/text/glyph_manager.cpp
+++ b/src/mbgl/text/glyph_manager.cpp
@@ -31,7 +31,7 @@ void GlyphManager::getGlyphs(GlyphRequestor& requestor, GlyphDependencies glyphD
Entry& entry = entries[fontStack];
const GlyphIDs& glyphIDs = dependency.second;
- GlyphRangeSet ranges;
+ std::unordered_set<GlyphRange> ranges;
for (const auto& glyphID : glyphIDs) {
if (localGlyphRasterizer->canRasterizeGlyph(fontStack, glyphID)) {
if (entry.glyphs.find(glyphID) == entry.glyphs.end()) {
diff --git a/src/mbgl/text/glyph_range.hpp b/src/mbgl/text/glyph_range.hpp
index 74afb73dfc..35a1f74b94 100644
--- a/src/mbgl/text/glyph_range.hpp
+++ b/src/mbgl/text/glyph_range.hpp
@@ -3,21 +3,24 @@
#include <utility>
#include <cstdint>
#include <unordered_set>
-#include <boost/functional/hash.hpp>
+#include <mbgl/util/hash.hpp>
namespace mbgl {
using GlyphRange = std::pair<uint16_t, uint16_t>;
-struct GlyphRangeHash {
- std::size_t operator()(const GlyphRange& glyphRange) const {
- return boost::hash_value(glyphRange);
- }
-};
-
-using GlyphRangeSet = std::unordered_set<GlyphRange, GlyphRangeHash>;
-
constexpr uint32_t GLYPHS_PER_GLYPH_RANGE = 256;
constexpr uint32_t GLYPH_RANGES_PER_FONT_STACK = 256;
} // end namespace mbgl
+
+namespace std {
+
+template <>
+struct hash<mbgl::GlyphRange> {
+ std::size_t operator()(const mbgl::GlyphRange& range) const {
+ return mbgl::util::hash(range.first, range.second);
+ }
+};
+
+} // namespace std
diff --git a/src/mbgl/tile/tile_id_hash.cpp b/src/mbgl/tile/tile_id_hash.cpp
index 4a1f185817..d4a7d88077 100644
--- a/src/mbgl/tile/tile_id_hash.cpp
+++ b/src/mbgl/tile/tile_id_hash.cpp
@@ -1,28 +1,27 @@
#include <mbgl/tile/tile_id.hpp>
-
-#include <boost/functional/hash.hpp>
+#include <mbgl/util/hash.hpp>
namespace std {
size_t hash<mbgl::CanonicalTileID>::operator()(const mbgl::CanonicalTileID& id) const {
std::size_t seed = 0;
- boost::hash_combine(seed, id.x);
- boost::hash_combine(seed, id.y);
- boost::hash_combine(seed, id.z);
+ mbgl::util::hash_combine(seed, id.x);
+ mbgl::util::hash_combine(seed, id.y);
+ mbgl::util::hash_combine(seed, id.z);
return seed;
}
size_t hash<mbgl::UnwrappedTileID>::operator()(const mbgl::UnwrappedTileID& id) const {
std::size_t seed = 0;
- boost::hash_combine(seed, std::hash<mbgl::CanonicalTileID>{}(id.canonical));
- boost::hash_combine(seed, id.wrap);
+ mbgl::util::hash_combine(seed, std::hash<mbgl::CanonicalTileID>{}(id.canonical));
+ mbgl::util::hash_combine(seed, id.wrap);
return seed;
}
size_t hash<mbgl::OverscaledTileID>::operator()(const mbgl::OverscaledTileID& id) const {
std::size_t seed = 0;
- boost::hash_combine(seed, std::hash<mbgl::CanonicalTileID>{}(id.canonical));
- boost::hash_combine(seed, id.overscaledZ);
+ mbgl::util::hash_combine(seed, std::hash<mbgl::CanonicalTileID>{}(id.canonical));
+ mbgl::util::hash_combine(seed, id.overscaledZ);
return seed;
}
diff --git a/src/mbgl/util/font_stack.cpp b/src/mbgl/util/font_stack.cpp
index fb1b716fb6..4093a21793 100644
--- a/src/mbgl/util/font_stack.cpp
+++ b/src/mbgl/util/font_stack.cpp
@@ -1,8 +1,8 @@
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
+#include <mbgl/util/hash.hpp>
-#include <boost/functional/hash.hpp>
#include <boost/algorithm/string/join.hpp>
namespace mbgl {
@@ -14,7 +14,11 @@ std::string fontStackToString(const FontStack& fontStack) {
}
FontStackHash FontStackHasher::operator()(const FontStack& fontStack) const {
- return boost::hash_range(fontStack.begin(), fontStack.end());
+ std::size_t seed = 0;
+ for (const auto& font : fontStack) {
+ util::hash_combine(seed, font);
+ }
+ return seed;
}
std::set<FontStack> fontStacks(const std::vector<Immutable<style::Layer::Impl>>& layers) {
diff --git a/src/mbgl/util/hash.hpp b/src/mbgl/util/hash.hpp
new file mode 100644
index 0000000000..987a8bd8dc
--- /dev/null
+++ b/src/mbgl/util/hash.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <mbgl/util/ignore.hpp>
+
+#include <functional>
+
+namespace mbgl {
+namespace util {
+
+template <class T>
+inline void hash_combine(std::size_t& seed, const T& v) {
+ seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+}
+
+template <class... Args>
+inline std::size_t hash(Args&&... args) {
+ std::size_t seed = 0;
+ ignore({ (hash_combine(seed, args), 0)... });
+ return seed;
+}
+
+} // namespace util
+} // namespace mbgl