From 37cb2bd756104923c8a055277a9d598710943e9f Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 19 Sep 2016 17:26:25 -0700 Subject: [PATCH] [core] Convert uses of std::set to std::unordered_set (#6325) * src/mbgl/annotation/annotation_manager.hpp * src/mbgl/algorithm/update_renderables.hpp * src/mbgl/geometry/glyph_atlas.hpp * src/mbgl/renderer/painter.cpp and src/mbgl/renderer/render_item.hpp * src/mbgl/renderer/symbol_bucket.hpp and src/mbgl/text/glyph_store.hpp * src/mbgl/sprite/sprite_atlas.hpp * include/mbgl/storage/network_status.hpp * src/mbgl/text/collision_tile.cpp * src/mbgl/style/update_batch.hpp * platform/default/mbgl/storage/offline_download.hpp * Add GlyphRangeSet typedef * Fix whitespace & unused imports --- include/mbgl/storage/network_status.hpp | 4 ++-- platform/default/mbgl/storage/offline_download.hpp | 4 ++-- src/mbgl/algorithm/update_renderables.hpp | 4 ++-- src/mbgl/annotation/annotation_manager.hpp | 6 +++--- src/mbgl/layout/symbol_layout.hpp | 4 ++-- src/mbgl/renderer/painter.cpp | 3 ++- src/mbgl/renderer/render_item.hpp | 4 ++-- src/mbgl/renderer/symbol_bucket.hpp | 1 - src/mbgl/sprite/sprite_atlas.hpp | 4 ++-- src/mbgl/storage/network_status.cpp | 2 +- src/mbgl/style/update_batch.hpp | 4 ++-- src/mbgl/text/collision_tile.cpp | 2 +- src/mbgl/text/glyph_atlas.cpp | 2 +- src/mbgl/text/glyph_atlas.hpp | 6 +++--- src/mbgl/text/glyph_range.hpp | 10 ++++++++++ test/text/glyph_atlas.cpp | 2 +- 16 files changed, 36 insertions(+), 26 deletions(-) diff --git a/include/mbgl/storage/network_status.hpp b/include/mbgl/storage/network_status.hpp index d7f502a3b..0d1ae54ec 100644 --- a/include/mbgl/storage/network_status.hpp +++ b/include/mbgl/storage/network_status.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include namespace mbgl { @@ -28,7 +28,7 @@ public: private: static std::atomic online; static std::mutex mtx; - static std::set observers; + static std::unordered_set observers; }; } // namespace mbgl diff --git a/platform/default/mbgl/storage/offline_download.hpp b/platform/default/mbgl/storage/offline_download.hpp index 27c5f0b13..77389d63d 100644 --- a/platform/default/mbgl/storage/offline_download.hpp +++ b/platform/default/mbgl/storage/offline_download.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include namespace mbgl { @@ -58,7 +58,7 @@ private: OfflineRegionStatus status; std::unique_ptr observer; std::list> requests; - std::set requiredSourceURLs; + std::unordered_set requiredSourceURLs; }; } // namespace mbgl diff --git a/src/mbgl/algorithm/update_renderables.hpp b/src/mbgl/algorithm/update_renderables.hpp index 5a6a26f98..fe2dc2c57 100644 --- a/src/mbgl/algorithm/update_renderables.hpp +++ b/src/mbgl/algorithm/update_renderables.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include namespace mbgl { namespace algorithm { @@ -21,7 +21,7 @@ void updateRenderables(GetTileFn getTile, const IdealTileIDs& idealTileIDs, const Range& zoomRange, const uint8_t dataTileZoom) { - std::set checked; + std::unordered_set checked; bool covered; int32_t overscaledZ; diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index b4959964f..856aeeed7 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include namespace mbgl { @@ -72,8 +72,8 @@ private: SymbolAnnotationTree symbolTree; SymbolAnnotationMap symbolAnnotations; ShapeAnnotationMap shapeAnnotations; - std::set obsoleteShapeAnnotationLayers; - std::set tiles; + std::unordered_set obsoleteShapeAnnotationLayers; + std::unordered_set tiles; SpriteAtlas spriteAtlas; }; diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index db27f1b81..c4e645579 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include namespace mbgl { @@ -88,7 +88,7 @@ private: bool sdfIcons = false; bool iconsNeedLinear = false; - std::set ranges; + GlyphRangeSet ranges; std::vector symbolInstances; std::vector features; }; diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 915f83f01..9822b6b91 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace mbgl { @@ -80,7 +81,7 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a RenderData renderData = style.getRenderData(frame.debugOptions); const std::vector& order = renderData.order; - const std::set& sources = renderData.sources; + const std::unordered_set& sources = renderData.sources; const Color& background = renderData.backgroundColor; // Update the default matrices to the current viewport dimensions. diff --git a/src/mbgl/renderer/render_item.hpp b/src/mbgl/renderer/render_item.hpp index 82ea89704..b4b1f4aec 100644 --- a/src/mbgl/renderer/render_item.hpp +++ b/src/mbgl/renderer/render_item.hpp @@ -2,7 +2,7 @@ #include -#include +#include #include namespace mbgl { @@ -31,7 +31,7 @@ public: class RenderData { public: Color backgroundColor; - std::set sources; + std::unordered_set sources; std::vector order; }; diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index 8f0c21bc9..ad53cd663 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -10,7 +10,6 @@ #include #include -#include #include namespace mbgl { diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp index d23d3a0fd..7a3c2c8b4 100644 --- a/src/mbgl/sprite/sprite_atlas.hpp +++ b/src/mbgl/sprite/sprite_atlas.hpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -140,7 +140,7 @@ private: std::recursive_mutex mtx; BinPack bin; std::map images; - std::set uninitialized; + std::unordered_set uninitialized; std::unique_ptr data; std::atomic dirtyFlag; bool fullUploadRequired = true; diff --git a/src/mbgl/storage/network_status.cpp b/src/mbgl/storage/network_status.cpp index 1ef5619bd..1bd392d57 100644 --- a/src/mbgl/storage/network_status.cpp +++ b/src/mbgl/storage/network_status.cpp @@ -11,7 +11,7 @@ namespace mbgl { std::atomic NetworkStatus::online(true); std::mutex NetworkStatus::mtx; -std::set NetworkStatus::observers; +std::unordered_set NetworkStatus::observers; NetworkStatus::Status NetworkStatus::Get() { if (online) { diff --git a/src/mbgl/style/update_batch.hpp b/src/mbgl/style/update_batch.hpp index ee82c98fd..562df52af 100644 --- a/src/mbgl/style/update_batch.hpp +++ b/src/mbgl/style/update_batch.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include namespace mbgl { @@ -8,7 +8,7 @@ namespace style { class UpdateBatch { public: - std::set sourceIDs; + std::unordered_set sourceIDs; }; } // namespace style diff --git a/src/mbgl/text/collision_tile.cpp b/src/mbgl/text/collision_tile.cpp index 982dff168..32a1a5474 100644 --- a/src/mbgl/text/collision_tile.cpp +++ b/src/mbgl/text/collision_tile.cpp @@ -156,7 +156,7 @@ Box CollisionTile::getTreeBox(const Point& anchor, const CollisionBox& bo std::vector CollisionTile::queryRenderedSymbols(const mapbox::geometry::box& box, const float scale) { std::vector result; - std::unordered_map> sourceLayerFeatures; + std::unordered_map> sourceLayerFeatures; auto anchor = util::matrixMultiply(rotationMatrix, convertPoint(box.min)); CollisionBox queryBox(anchor, 0, 0, box.max.x - box.min.x, box.max.y - box.min.y, scale); diff --git a/src/mbgl/text/glyph_atlas.cpp b/src/mbgl/text/glyph_atlas.cpp index 9e92e3e81..f46c156b2 100644 --- a/src/mbgl/text/glyph_atlas.cpp +++ b/src/mbgl/text/glyph_atlas.cpp @@ -39,7 +39,7 @@ void GlyphAtlas::requestGlyphRange(const FontStack& fontStack, const GlyphRange& std::make_unique(this, fontStack, range, observer, fileSource)); } -bool GlyphAtlas::hasGlyphRanges(const FontStack& fontStack, const std::set& glyphRanges) { +bool GlyphAtlas::hasGlyphRanges(const FontStack& fontStack, const GlyphRangeSet& glyphRanges) { if (glyphRanges.empty()) { return true; } diff --git a/src/mbgl/text/glyph_atlas.hpp b/src/mbgl/text/glyph_atlas.hpp index ca88d16f8..5c6cbf45f 100644 --- a/src/mbgl/text/glyph_atlas.hpp +++ b/src/mbgl/text/glyph_atlas.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include @@ -41,7 +41,7 @@ public: // made and when the glyph if finally parsed, it gets added to the respective // GlyphSet and a signal is emitted to notify the observers. This method // can be called from any thread. - bool hasGlyphRanges(const FontStack&, const std::set&); + bool hasGlyphRanges(const FontStack&, const GlyphRangeSet&); void setURL(const std::string &url) { glyphURL = url; @@ -95,7 +95,7 @@ private: GlyphValue(Rect rect_, uintptr_t id) : rect(std::move(rect_)), ids({ id }) {} Rect rect; - std::set ids; + std::unordered_set ids; }; std::mutex mtx; diff --git a/src/mbgl/text/glyph_range.hpp b/src/mbgl/text/glyph_range.hpp index 644046d7f..aa11b35f5 100644 --- a/src/mbgl/text/glyph_range.hpp +++ b/src/mbgl/text/glyph_range.hpp @@ -2,9 +2,19 @@ #include #include +#include +#include namespace mbgl { typedef std::pair GlyphRange; +struct GlyphRangeHash { + std::size_t operator()(const GlyphRange& glyphRange) const { + return boost::hash_value(glyphRange); + } +}; + +typedef std::unordered_set GlyphRangeSet; + } // end namespace mbgl diff --git a/test/text/glyph_atlas.cpp b/test/text/glyph_atlas.cpp index 27d43a172..8634cbe91 100644 --- a/test/text/glyph_atlas.cpp +++ b/test/text/glyph_atlas.cpp @@ -18,7 +18,7 @@ public: StubStyleObserver observer; GlyphAtlas glyphAtlas { 32, 32, fileSource }; - void run(const std::string& url, const FontStack& fontStack, const std::set& glyphRanges) { + void run(const std::string& url, const FontStack& fontStack, const GlyphRangeSet& glyphRanges) { // Squelch logging. Log::setObserver(std::make_unique());