use unordered map, don't make copies (auto usage!) and swap maps

This commit is contained in:
Konstantin Käfer
2014-05-26 18:40:47 +02:00
parent 65bffccfd9
commit 1b58fb30a3
7 changed files with 36 additions and 35 deletions

View File

@@ -12,6 +12,7 @@
#include <llmr/util/uv.hpp>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <memory>
@@ -52,12 +53,12 @@ public:
std::set<std::string> appliedClasses;
struct {
BackgroundProperties background;
std::map<std::string, FillProperties> fills;
std::map<std::string, LineProperties> lines;
std::map<std::string, IconProperties> icons;
std::map<std::string, TextProperties> texts;
std::map<std::string, RasterProperties> rasters;
std::map<std::string, CompositeProperties> composites;
std::unordered_map<std::string, FillProperties> fills;
std::unordered_map<std::string, LineProperties> lines;
std::unordered_map<std::string, IconProperties> icons;
std::unordered_map<std::string, TextProperties> texts;
std::unordered_map<std::string, RasterProperties> rasters;
std::unordered_map<std::string, CompositeProperties> composites;
std::map<std::string, std::map<TransitionablePropertyKey, std::string>> effective_classes;
} computed;
@@ -74,24 +75,24 @@ private:
// Last applied settings.
struct {
BackgroundProperties background;
std::map<std::string, FillProperties> fills;
std::map<std::string, LineProperties> lines;
std::map<std::string, IconProperties> icons;
std::map<std::string, TextProperties> texts;
std::map<std::string, RasterProperties> rasters;
std::map<std::string, CompositeProperties> composites;
std::unordered_map<std::string, FillProperties> fills;
std::unordered_map<std::string, LineProperties> lines;
std::unordered_map<std::string, IconProperties> icons;
std::unordered_map<std::string, TextProperties> texts;
std::unordered_map<std::string, RasterProperties> rasters;
std::unordered_map<std::string, CompositeProperties> composites;
std::map<std::string, std::map<TransitionablePropertyKey, std::string>> effective_classes;
} previous;
// Settings values currently being transitioned.
struct {
BackgroundProperties background;
std::map<std::string, FillProperties> fills;
std::map<std::string, LineProperties> lines;
std::map<std::string, IconProperties> icons;
std::map<std::string, TextProperties> texts;
std::map<std::string, RasterProperties> rasters;
std::map<std::string, CompositeProperties> composites;
std::unordered_map<std::string, FillProperties> fills;
std::unordered_map<std::string, LineProperties> lines;
std::unordered_map<std::string, IconProperties> icons;
std::unordered_map<std::string, TextProperties> texts;
std::unordered_map<std::string, RasterProperties> rasters;
std::unordered_map<std::string, CompositeProperties> composites;
} transitioning;
std::map<std::string, std::map<TransitionablePropertyKey, PropertyTransition>> properties_to_transition;

View File

@@ -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<std::string, FillProperties> &fill_properties = map.getStyle().computed.fills;
const std::unordered_map<std::string, FillProperties>::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;

View File

@@ -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<std::string, IconProperties> &icon_properties = map.getStyle().computed.icons;
const std::unordered_map<std::string, IconProperties>::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;

View File

@@ -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<std::string, LineProperties> &line_properties = map.getStyle().computed.lines;
const std::unordered_map<std::string, LineProperties>::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;

View File

@@ -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<std::string, RasterProperties> &raster_properties = map.getStyle().computed.rasters;
const std::unordered_map<std::string, RasterProperties>::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;

View File

@@ -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<std::string, TextProperties> &text_properties = map.getStyle().computed.texts;
const std::unordered_map<std::string, TextProperties>::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;

View File

@@ -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();