Skip to content

Commit

Permalink
for best perf prefer unique_ptr over shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Apr 4, 2016
1 parent 85cba87 commit f8e60ab
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/vector_tile_load_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace vector_tile_impl

void merge_from_buffer(merc_tile & t, const char * data, std::size_t size)
{
using ds_ptr = std::shared_ptr<mapnik::vector_tile_impl::tile_datasource_pbf>;
using ds_ptr = std::unique_ptr<mapnik::vector_tile_impl::tile_datasource_pbf>;
protozero::pbf_reader tile_msg(data, size);
std::vector<ds_ptr> ds_vec;
while (tile_msg.next())
Expand Down Expand Up @@ -57,7 +57,7 @@ void merge_from_buffer(merc_tile & t, const char * data, std::size_t size)
{
// v1 tiles will be converted to v2
protozero::pbf_reader layer_msg(layer_data);
ds_vec.push_back(std::make_shared<mapnik::vector_tile_impl::tile_datasource_pbf>(
ds_vec.push_back(std::make_unique<mapnik::vector_tile_impl::tile_datasource_pbf>(
layer_msg,
t.x(),
t.y(),
Expand All @@ -83,7 +83,7 @@ void merge_from_buffer(merc_tile & t, const char * data, std::size_t size)
std::int32_t prev_buffer_size = t.buffer_size();
t.buffer_size(4096); // very large buffer so we don't miss any buffered points
mapnik::Map map(t.tile_size(), t.tile_size(), "+init=epsg:3857");
for (auto ds : ds_vec)
for (auto const& ds : ds_vec)
{
ds->set_envelope(t.get_buffered_extent());
mapnik::layer lyr(ds->get_name(), "+init=epsg:3857");
Expand Down

2 comments on commit f8e60ab

@springmeyer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @flippmoke - shared_ptr should be fast enough that we'd never be able to prove unique_ptr is faster in this case. However using unique_ptr prevents copies which caught that the shared pointers were being copied (and therefore unnecessarily reference counted) in the for loop.

@springmeyer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, total brain fade: these obviously need to be shared_ptr to be convertible to mapnik::datasource_ptr. Ticketed getting tests that actually ensure this file compiles at #192. Reverted in 0c724f1

Please sign in to comment.