From d27b45553a2aa1f0dd6e2d7472e708f79a5a85a7 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 5 Aug 2014 15:19:37 -0700 Subject: [PATCH] use emplace/emplace_back over insert/push_back - refs #2336 --- include/mapnik/attribute_collector.hpp | 6 +++--- include/mapnik/feature.hpp | 4 ++-- .../renderer_common/process_group_symbolizer.hpp | 2 +- include/mapnik/symbolizer.hpp | 7 ++----- include/mapnik/util/geometry_to_wkb.hpp | 4 ++-- include/mapnik/xml_attribute_cast.hpp | 2 +- plugins/input/postgis/postgis_datasource.cpp | 2 +- plugins/input/python/python_datasource.cpp | 2 +- src/cairo/cairo_context.cpp | 3 +-- src/datasource_cache.cpp | 2 +- src/font_engine_freetype.cpp | 6 +++--- src/grid/grid.cpp | 4 ++-- src/load_map.cpp | 2 +- src/map.cpp | 4 ++-- src/mapped_memory_cache.cpp | 6 ++---- src/marker_cache.cpp | 12 ++++++------ src/text/face.cpp | 2 +- src/text/formatting/registry.cpp | 2 +- src/text/placements/registry.cpp | 2 +- src/xml_tree.cpp | 2 +- 20 files changed, 35 insertions(+), 41 deletions(-) diff --git a/include/mapnik/attribute_collector.hpp b/include/mapnik/attribute_collector.hpp index 16d397ca4..2e0eec6cf 100644 --- a/include/mapnik/attribute_collector.hpp +++ b/include/mapnik/attribute_collector.hpp @@ -56,7 +56,7 @@ struct expression_attributes : boost::static_visitor void operator() (attribute const& attr) const { - names_.insert(attr.name()); + names_.emplace(attr.name()); } template @@ -289,7 +289,7 @@ inline void group_attribute_collector::operator() (group_symbolizer const& sym) { std::string col_idx_name = col_name; boost::replace_all(col_idx_name, "%", col_idx_str); - names_.insert(col_idx_name); + names_.emplace(col_idx_name); } } } @@ -298,7 +298,7 @@ inline void group_attribute_collector::operator() (group_symbolizer const& sym) { // This is not an indexed column, or we are ignoring indexes. // Insert the name as is. - names_.insert(col_name); + names_.emplace(col_name); } } } diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index 10be7d64f..9547ba86b 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -67,13 +67,13 @@ public: inline size_type push(key_type const& name) { size_type index = mapping_.size(); - mapping_.insert(std::make_pair(name, index)); + mapping_.emplace(name, index); return index; } inline void add(key_type const& name, size_type index) { - mapping_.insert(std::make_pair(name, index)); + mapping_.emplace(name, index); } inline size_type size() const { return mapping_.size(); } diff --git a/include/mapnik/renderer_common/process_group_symbolizer.hpp b/include/mapnik/renderer_common/process_group_symbolizer.hpp index c4cc390d3..abf13dbfc 100644 --- a/include/mapnik/renderer_common/process_group_symbolizer.hpp +++ b/include/mapnik/renderer_common/process_group_symbolizer.hpp @@ -268,7 +268,7 @@ void render_group_symbolizer(group_symbolizer const& sym, *(rule->get_filter())).to_bool()) { // add matched rule and feature to the list of things to draw - matches.push_back(std::make_pair(rule, sub_feature)); + matches.emplace_back(rule, sub_feature); // construct a bounding box around all symbolizers for the matched rule bound_box bounds; diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index 56a55e852..a84d7c7be 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -311,10 +311,7 @@ struct put_impl } else { - // NOTE: we use insert here instead of emplace - // because of lacking std::map emplace support in libstdc++ - // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44436 - sym.properties.insert(std::make_pair(key, enumeration_wrapper(val))); + sym.properties.emplace(key, enumeration_wrapper(val)); } } }; @@ -331,7 +328,7 @@ struct put_impl } else { - sym.properties.insert(std::make_pair(key, val)); + sym.properties.emplace(key, val); } } }; diff --git a/include/mapnik/util/geometry_to_wkb.hpp b/include/mapnik/util/geometry_to_wkb.hpp index ff89bd721..53245aecb 100644 --- a/include/mapnik/util/geometry_to_wkb.hpp +++ b/include/mapnik/util/geometry_to_wkb.hpp @@ -196,13 +196,13 @@ wkb_buffer_ptr to_polygon_wkb( GeometryType const& g, wkbByteOrder byte_order) if (command == SEG_MOVETO) { rings.push_back(new linear_ring); // start new loop - rings.back().push_back(std::make_pair(x,y)); + rings.back().emplace_back(x,y); size += 4; // num_points size += 2 * 8; // point } else if (command == SEG_LINETO) { - rings.back().push_back(std::make_pair(x,y)); + rings.back().emplace_back(x,y); size += 2 * 8; // point } } diff --git a/include/mapnik/xml_attribute_cast.hpp b/include/mapnik/xml_attribute_cast.hpp index 9398b4ff8..2e4c666b1 100644 --- a/include/mapnik/xml_attribute_cast.hpp +++ b/include/mapnik/xml_attribute_cast.hpp @@ -194,7 +194,7 @@ struct do_xml_attribute_cast else { mapnik::expression_ptr expr = parse_expression(source); - tree.expr_cache_.insert(std::make_pair(source,expr)); + tree.expr_cache_.emplace(source,expr); return expr; } } diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index 9ca1756f0..5ce128af3 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -684,7 +684,7 @@ processor_context_ptr postgis_datasource::get_context(feature_style_context_map } else { - return ctx.insert(std::make_pair(ds_name,std::make_shared())).first->second; + return ctx.emplace(ds_name,std::make_shared()).first->second; } } diff --git a/plugins/input/python/python_datasource.cpp b/plugins/input/python/python_datasource.cpp index 4cd7813bd..dbc964e80 100644 --- a/plugins/input/python/python_datasource.cpp +++ b/plugins/input/python/python_datasource.cpp @@ -29,7 +29,7 @@ python_datasource::python_datasource(parameters const& params) { if((kv.first != "type") && (kv.first != "factory")) { - kwargs_.insert(std::make_pair(kv.first, *params.get(kv.first))); + kwargs_.emplace(kv.first, *params.get(kv.first)); } } diff --git a/src/cairo/cairo_context.cpp b/src/cairo/cairo_context.cpp index c0f5978f0..3a908ef8f 100644 --- a/src/cairo/cairo_context.cpp +++ b/src/cairo/cairo_context.cpp @@ -525,9 +525,8 @@ cairo_face_ptr cairo_face_manager::get_face(face_ptr face) else { entry = std::make_shared(font_engine_, face); - cache_.insert(std::make_pair(face, entry)); + cache_.emplace(face, entry); } - return entry; } diff --git a/src/datasource_cache.cpp b/src/datasource_cache.cpp index 3c6b0c4e4..08af17caa 100644 --- a/src/datasource_cache.cpp +++ b/src/datasource_cache.cpp @@ -224,7 +224,7 @@ bool datasource_cache::register_datasource(std::string const& filename) } else { - if (plugins_.insert(std::make_pair(plugin->name(),plugin)).second) + if (plugins_.emplace(plugin->name(),plugin).second) { MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Registered=" diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index da78888f0..87209f569 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -177,7 +177,7 @@ bool freetype_engine::register_font_impl(std::string const& file_name, FT_Librar // skip fonts with leading . in the name if (!boost::algorithm::starts_with(name,".")) { - name2file_.insert(std::make_pair(name, std::make_pair(i,file_name))); + name2file_.emplace(name,std::make_pair(i,file_name)); success = true; } } @@ -332,7 +332,7 @@ face_ptr freetype_engine::create_face(std::string const& family_name) std::fseek(file.get(), 0, SEEK_SET); std::unique_ptr buffer(new char[file_size]); std::fread(buffer.get(), file_size, 1, file.get()); - auto result = memory_fonts_.insert(std::make_pair(itr->second.second, std::make_pair(std::move(buffer),file_size))); + auto result = memory_fonts_.emplace(itr->second.second, std::make_pair(std::move(buffer),file_size)); FT_Error error = FT_New_Memory_Face (library_, reinterpret_cast(result.first->second.first.get()), static_cast(result.first->second.second), @@ -377,7 +377,7 @@ face_ptr face_manager::get_face(std::string const& name) face_ptr face = engine_.create_face(name); if (face) { - face_ptr_cache_.insert(make_pair(name,face)); + face_ptr_cache_.emplace(name,face); } return face; } diff --git a/src/grid/grid.cpp b/src/grid/grid.cpp index 96ead5719..208fe663e 100644 --- a/src/grid/grid.cpp +++ b/src/grid/grid.cpp @@ -127,7 +127,7 @@ void hit_grid::add_feature(mapnik::feature_impl const& feature) { // TODO - consider shortcutting f_keys if feature_id == lookup_value // create a mapping between the pixel id and the feature key - f_keys_.insert(std::make_pair(feature_id,lookup_value)); + f_keys_.emplace(feature_id,lookup_value); // if extra fields have been supplied, push them into grid memory if (!names_.empty()) { @@ -136,7 +136,7 @@ void hit_grid::add_feature(mapnik::feature_impl const& feature) // https://github.com/mapnik/mapnik/issues/1198 mapnik::feature_ptr feature2(mapnik::feature_factory::create(ctx_,feature_id)); feature2->set_data(feature.get_data()); - features_.insert(std::make_pair(lookup_value,feature2)); + features_.emplace(lookup_value,feature2); } } else diff --git a/src/load_map.cpp b/src/load_map.cpp index aa03500b8..5ae2c2349 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -501,7 +501,7 @@ void map_parser::parse_fontset(Map & map, xml_node const& node) // XXX Hack because map object isn't accessible by text_symbolizer // when it's parsed - fontsets_.insert(std::make_pair(name, fontset)); + fontsets_.emplace(name, fontset); map.insert_fontset(name, std::move(fontset)); } catch (config_error const& ex) diff --git a/src/map.cpp b/src/map.cpp index d3163f49f..227544c76 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -201,7 +201,7 @@ Map::const_style_iterator Map::end_styles() const bool Map::insert_style(std::string const& name,feature_type_style style) { - return styles_.insert(make_pair(name, std::move(style))).second; + return styles_.emplace(name, std::move(style)).second; } void Map::remove_style(std::string const& name) @@ -224,7 +224,7 @@ bool Map::insert_fontset(std::string const& name, font_set fontset) { throw mapnik::config_error("Fontset name must match the name used to reference it on the map"); } - return fontsets_.insert(make_pair(name, std::move(fontset))).second; + return fontsets_.emplace(name, std::move(fontset)).second; } boost::optional Map::find_fontset(std::string const& name) const diff --git a/src/mapped_memory_cache.cpp b/src/mapped_memory_cache.cpp index 96bce78ad..36b2aa8d0 100644 --- a/src/mapped_memory_cache.cpp +++ b/src/mapped_memory_cache.cpp @@ -48,7 +48,7 @@ bool mapped_memory_cache::insert(std::string const& uri, mapped_region_ptr mem) #ifdef MAPNIK_THREADSAFE mapnik::scoped_lock lock(mutex_); #endif - return cache_.insert(std::make_pair(uri,mem)).second; + return cache_.emplace(uri,mem).second; } boost::optional mapped_memory_cache::find(std::string const& uri, bool update_cache) @@ -71,12 +71,10 @@ boost::optional mapped_memory_cache::find(std::string const& { boost::interprocess::file_mapping mapping(uri.c_str(),boost::interprocess::read_only); mapped_region_ptr region(std::make_shared(mapping,boost::interprocess::read_only)); - result.reset(region); - if (update_cache) { - cache_.insert(std::make_pair(uri,*result)); + cache_.emplace(uri,*result); } return result; } diff --git a/src/marker_cache.cpp b/src/marker_cache.cpp index 6620efcc8..f64ae152e 100644 --- a/src/marker_cache.cpp +++ b/src/marker_cache.cpp @@ -61,7 +61,7 @@ marker_cache::marker_cache() boost::optional bitmap_data = boost::optional(std::make_shared(4,4)); (*bitmap_data)->set(0xff000000); marker_ptr mark = std::make_shared(bitmap_data); - marker_cache_.insert(std::make_pair("image://square",mark)); + marker_cache_.emplace("image://square",mark); } marker_cache::~marker_cache() {} @@ -103,7 +103,7 @@ bool marker_cache::insert_svg(std::string const& name, std::string const& svg_st iterator_type itr = svg_cache_.find(key); if (itr == svg_cache_.end()) { - return svg_cache_.insert(std::make_pair(key,svg_string)).second; + return svg_cache_.emplace(key,svg_string).second; } return false; } @@ -113,7 +113,7 @@ bool marker_cache::insert_marker(std::string const& uri, marker_ptr path) #ifdef MAPNIK_THREADSAFE mapnik::scoped_lock lock(mutex_); #endif - return marker_cache_.insert(std::make_pair(uri,path)).second; + return marker_cache_.emplace(uri,path).second; } boost::optional marker_cache::find(std::string const& uri, @@ -165,7 +165,7 @@ boost::optional marker_cache::find(std::string const& uri, result.reset(mark); if (update_cache) { - marker_cache_.insert(std::make_pair(uri,*result)); + marker_cache_.emplace(uri,*result); } } // otherwise assume file-based @@ -194,7 +194,7 @@ boost::optional marker_cache::find(std::string const& uri, result.reset(mark); if (update_cache) { - marker_cache_.insert(std::make_pair(uri,*result)); + marker_cache_.emplace(uri,*result); } } else @@ -218,7 +218,7 @@ boost::optional marker_cache::find(std::string const& uri, result.reset(mark); if (update_cache) { - marker_cache_.insert(std::make_pair(uri,*result)); + marker_cache_.emplace(uri,*result); } } else diff --git a/src/text/face.cpp b/src/text/face.cpp index 3f57bc89a..20d487317 100644 --- a/src/text/face.cpp +++ b/src/text/face.cpp @@ -94,7 +94,7 @@ bool font_face::glyph_dimensions(glyph_info & glyph) const glyph.unscaled_ymax = glyph_bbox.yMax; glyph.unscaled_advance = face_->glyph->advance.x; glyph.unscaled_line_height = face_->size->metrics.height; - glyph_info_cache_.insert(std::make_pair(glyph.glyph_index, glyph)); + glyph_info_cache_.emplace(glyph.glyph_index, glyph); return true; } diff --git a/src/text/formatting/registry.cpp b/src/text/formatting/registry.cpp index fe653e265..86ffb25fd 100644 --- a/src/text/formatting/registry.cpp +++ b/src/text/formatting/registry.cpp @@ -44,7 +44,7 @@ void registry::register_name(std::string const& name, from_xml_function_ptr ptr, if (overwrite) { map_[name] = ptr; } else { - map_.insert(make_pair(name, ptr)); + map_.emplace(name, ptr); } } diff --git a/src/text/placements/registry.cpp b/src/text/placements/registry.cpp index adbd662d7..95ebd1e88 100644 --- a/src/text/placements/registry.cpp +++ b/src/text/placements/registry.cpp @@ -42,7 +42,7 @@ void registry::register_name(std::string name, from_xml_function_ptr ptr, bool o if (overwrite) { map_[name] = ptr; } else { - map_.insert(make_pair(name, ptr)); + map_.emplace(name, ptr); } } diff --git a/src/xml_tree.cpp b/src/xml_tree.cpp index 1c7ee10b9..f2f79bb85 100644 --- a/src/xml_tree.cpp +++ b/src/xml_tree.cpp @@ -226,7 +226,7 @@ xml_node &xml_node::add_child(std::string && name, unsigned line, bool is_text) void xml_node::add_attribute(const char * name, const char * value) { - attributes_.insert(std::make_pair(name,xml_attribute(value))); + attributes_.emplace(name,xml_attribute(value)); } xml_node::attribute_map const& xml_node::get_attributes() const