From 1b58fb30a3205e68f03f021e8c4314cf59629683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 26 May 2014 18:40:47 +0200 Subject: [PATCH] use unordered map, don't make copies (auto usage!) and swap maps --- include/llmr/style/style.hpp | 37 +++++++++++++++++---------------- src/renderer/painter_fill.cpp | 4 ++-- src/renderer/painter_icon.cpp | 4 ++-- src/renderer/painter_line.cpp | 4 ++-- src/renderer/painter_raster.cpp | 4 ++-- src/renderer/painter_text.cpp | 4 ++-- src/style/style.cpp | 14 ++++++------- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index 4aa4b748b..048c4d545 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -52,12 +53,12 @@ public: std::set appliedClasses; struct { BackgroundProperties background; - std::map fills; - std::map lines; - std::map icons; - std::map texts; - std::map rasters; - std::map composites; + std::unordered_map fills; + std::unordered_map lines; + std::unordered_map icons; + std::unordered_map texts; + std::unordered_map rasters; + std::unordered_map composites; std::map> effective_classes; } computed; @@ -74,24 +75,24 @@ private: // Last applied settings. struct { BackgroundProperties background; - std::map fills; - std::map lines; - std::map icons; - std::map texts; - std::map rasters; - std::map composites; + std::unordered_map fills; + std::unordered_map lines; + std::unordered_map icons; + std::unordered_map texts; + std::unordered_map rasters; + std::unordered_map composites; std::map> effective_classes; } previous; // Settings values currently being transitioned. struct { BackgroundProperties background; - std::map fills; - std::map lines; - std::map icons; - std::map texts; - std::map rasters; - std::map composites; + std::unordered_map fills; + std::unordered_map lines; + std::unordered_map icons; + std::unordered_map texts; + std::unordered_map rasters; + std::unordered_map composites; } transitioning; std::map> properties_to_transition; diff --git a/src/renderer/painter_fill.cpp b/src/renderer/painter_fill.cpp index b52f8c396..5f014dc01 100644 --- a/src/renderer/painter_fill.cpp +++ b/src/renderer/painter_fill.cpp @@ -144,8 +144,8 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons // Abort early. if (!bucket.hasData()) return; - auto fill_properties = map.getStyle().computed.fills; - auto fill_properties_it = fill_properties.find(layer_name); + const std::unordered_map &fill_properties = map.getStyle().computed.fills; + const std::unordered_map::const_iterator fill_properties_it = fill_properties.find(layer_name); if (fill_properties_it == fill_properties.end()) return; const FillProperties& properties = fill_properties_it->second; diff --git a/src/renderer/painter_icon.cpp b/src/renderer/painter_icon.cpp index b5f4964e6..382312c12 100644 --- a/src/renderer/painter_icon.cpp +++ b/src/renderer/painter_icon.cpp @@ -11,8 +11,8 @@ void Painter::renderIcon(IconBucket& bucket, const std::string& layer_name, cons if (!bucket.hasData()) return; if (pass == Opaque) return; - auto icon_properties = map.getStyle().computed.icons; - auto icon_properties_it = icon_properties.find(layer_name); + const std::unordered_map &icon_properties = map.getStyle().computed.icons; + const std::unordered_map::const_iterator icon_properties_it = icon_properties.find(layer_name); if (icon_properties_it == icon_properties.end()) return; const IconProperties& properties = icon_properties_it->second; diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index 8dc486201..2788a8bb1 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -9,8 +9,8 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons if (pass == Opaque) return; if (!bucket.hasData()) return; - auto line_properties = map.getStyle().computed.lines; - auto line_properties_it = line_properties.find(layer_name); + const std::unordered_map &line_properties = map.getStyle().computed.lines; + const std::unordered_map::const_iterator line_properties_it = line_properties.find(layer_name); if (line_properties_it == line_properties.end()) return; const LineProperties& properties = line_properties_it->second; diff --git a/src/renderer/painter_raster.cpp b/src/renderer/painter_raster.cpp index b877496e0..de0d35261 100644 --- a/src/renderer/painter_raster.cpp +++ b/src/renderer/painter_raster.cpp @@ -7,8 +7,8 @@ using namespace llmr; void Painter::renderRaster(RasterBucket& bucket, const std::string& layer_name, const Tile::ID& /*id*/) { if (pass == Translucent) return; - auto raster_properties = map.getStyle().computed.rasters; - auto raster_properties_it = raster_properties.find(layer_name); + const std::unordered_map &raster_properties = map.getStyle().computed.rasters; + const std::unordered_map::const_iterator raster_properties_it = raster_properties.find(layer_name); if (raster_properties_it == raster_properties.end()) return; const RasterProperties& properties = raster_properties_it->second; diff --git a/src/renderer/painter_text.cpp b/src/renderer/painter_text.cpp index f2e458d8c..0c3c0a01b 100644 --- a/src/renderer/painter_text.cpp +++ b/src/renderer/painter_text.cpp @@ -9,8 +9,8 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons if (pass == Opaque) return; if (!bucket.hasData()) return; - auto text_properties = map.getStyle().computed.texts; - auto text_properties_it = text_properties.find(layer_name); + const std::unordered_map &text_properties = map.getStyle().computed.texts; + const std::unordered_map::const_iterator text_properties_it = text_properties.find(layer_name); if (text_properties_it == text_properties.end()) return; const TextProperties& properties = text_properties_it->second; diff --git a/src/style/style.cpp b/src/style/style.cpp index 7f9b6ba78..38b8f1723 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -74,15 +74,15 @@ void Style::cascade(float z) { time start = util::now(); - previous.fills = computed.fills; - previous.lines = computed.lines; - previous.icons = computed.icons; - previous.texts = computed.texts; - previous.rasters = computed.rasters; - previous.composites = computed.composites; + previous.fills.swap(computed.fills); + previous.lines.swap(computed.lines); + previous.icons.swap(computed.icons); + previous.texts.swap(computed.texts); + previous.rasters.swap(computed.rasters); + previous.composites.swap(computed.composites); previous.background = computed.background; - previous.effective_classes = computed.effective_classes; + previous.effective_classes.swap(computed.effective_classes); reset();