From aae56fa387cde108a3a1cfa3a7a38cbe1776bf34 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 1 Oct 2014 14:09:09 -0700 Subject: [PATCH] avoid style, layer, and fontset copies in load_map - refs #2453 --- include/mapnik/map.hpp | 33 +++++++++++++++++++++++++++------ src/map.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/include/mapnik/map.hpp b/include/mapnik/map.hpp index da2ac10ce..e65435020 100644 --- a/include/mapnik/map.hpp +++ b/include/mapnik/map.hpp @@ -166,13 +166,21 @@ public: */ style_iterator end_styles(); - /*! \brief Insert a style in the map. + /*! \brief Insert a style in the map by copying. * @param name The name of the style. * @param style The style to insert. * @return true If success. * false If no success. */ - bool insert_style(std::string const& name,feature_type_style style); + bool insert_style(std::string const& name,feature_type_style const& style); + + /*! \brief Insert a style in the map by moving.. + * @param name The name of the style. + * @param style The style to insert. + * @return true If success. + * false If no success. + */ + bool insert_style(std::string const& name,feature_type_style && style); /*! \brief Remove a style from the map. * @param name The name of the style. @@ -185,13 +193,21 @@ public: */ boost::optional find_style(std::string const& name) const; - /*! \brief Insert a fontset into the map. + /*! \brief Insert a fontset into the map by copying. * @param name The name of the fontset. * @param fontset The fontset to insert. * @return true If success. * false If failure. */ - bool insert_fontset(std::string const& name, font_set fontset); + bool insert_fontset(std::string const& name, font_set const& fontset); + + /*! \brief Insert a fontset into the map by moving. + * @param name The name of the fontset. + * @param fontset The fontset to insert. + * @return true If success. + * false If failure. + */ + bool insert_fontset(std::string const& name, font_set && fontset); /*! \brief Find a fontset. * @param name The name of the fontset. @@ -213,10 +229,15 @@ public: */ size_t layer_count() const; - /*! \brief Add a layer to the map. + /*! \brief Add a layer to the map by copying it. * @param l The layer to add. */ - void add_layer(layer l); + void add_layer(layer const& l); + + /*! \brief Add a layer to the map by moving it. + * @param l The layer to add. + */ + void insert_layer(layer && l); /*! \brief Get a layer. * @param index layer number. diff --git a/src/map.cpp b/src/map.cpp index a58bb51f6..c4b6cd687 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -200,7 +200,12 @@ Map::const_style_iterator Map::end_styles() const return styles_.end(); } -bool Map::insert_style(std::string const& name,feature_type_style style) +bool Map::insert_style(std::string const& name, feature_type_style const& style) +{ + return styles_.emplace(name, style).second; +} + +bool Map::insert_style(std::string const& name, feature_type_style && style) { return styles_.emplace(name, std::move(style)).second; } @@ -219,7 +224,16 @@ boost::optional Map::find_style(std::string const& na return boost::optional() ; } -bool Map::insert_fontset(std::string const& name, font_set fontset) +bool Map::insert_fontset(std::string const& name, font_set const& fontset) +{ + if (fontset.get_name() != name) + { + throw mapnik::config_error("Fontset name must match the name used to reference it on the map"); + } + return fontsets_.emplace(name, fontset).second; +} + +bool Map::insert_fontset(std::string const& name, font_set && fontset) { if (fontset.get_name() != name) { @@ -252,7 +266,12 @@ size_t Map::layer_count() const return layers_.size(); } -void Map::add_layer(layer l) +void Map::add_layer(layer const& l) +{ + layers_.emplace_back(l); +} + +void Map::insert_layer(layer && l) { layers_.push_back(std::move(l)); }