Skip to content

Commit b55f768

Browse files
committed
output-pgsql: use fixed array for tables
Vectors are not necessary here as the size is known at compiletime.
1 parent 42eae3c commit b55f768

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

output-pgsql.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void output_pgsql_t::stop(osmium::thread::Pool *pool)
243243
{
244244
// attempt to stop tables in parallel
245245
for (auto &t : m_tables) {
246-
pool->submit(std::bind(&table_t::stop, t));
246+
pool->submit(std::bind(&table_t::stop, t.get()));
247247
}
248248

249249
if (m_options.expire_tiles_zoom_min > 0) {
@@ -492,10 +492,9 @@ int output_pgsql_t::relation_modify(osmium::Relation const &rel)
492492

493493
int output_pgsql_t::start()
494494
{
495-
for(std::vector<std::shared_ptr<table_t> >::iterator table = m_tables.begin(); table != m_tables.end(); ++table)
496-
{
495+
for (auto &t : m_tables) {
497496
//setup the table in postgres
498-
table->get()->start();
497+
t->start();
499498
}
500499

501500
return 0;
@@ -529,7 +528,6 @@ output_pgsql_t::output_pgsql_t(std::shared_ptr<middle_query_t> const &mid,
529528
}
530529

531530
//for each table
532-
m_tables.reserve(t_MAX);
533531
for (int i = 0; i < t_MAX; i++) {
534532

535533
//figure out the columns this table needs
@@ -566,12 +564,12 @@ output_pgsql_t::output_pgsql_t(std::shared_ptr<middle_query_t> const &mid,
566564
//tremble in awe of this massive constructor! seriously we are trying to avoid passing an
567565
//options object because we want to make use of the table_t in output_mutli_t which could
568566
//have a different tablespace/hstores/etc per table
569-
m_tables.push_back(std::shared_ptr<table_t>(new table_t(
567+
m_tables[i].reset(new table_t(
570568
m_options.database_options.conninfo(), name, type, columns,
571569
m_options.hstore_columns, m_options.projection->target_srs(),
572570
m_options.append, m_options.slim, m_options.droptemp,
573571
m_options.hstore_mode, m_options.enable_hstore_index,
574-
m_options.tblsmain_data, m_options.tblsmain_index)));
572+
m_options.tblsmain_data, m_options.tblsmain_index));
575573
}
576574
}
577575

@@ -590,9 +588,9 @@ output_pgsql_t::output_pgsql_t(output_pgsql_t const *other,
590588
buffer(1024, osmium::memory::Buffer::auto_grow::yes),
591589
rels_buffer(1024, osmium::memory::Buffer::auto_grow::yes)
592590
{
593-
for (auto const &t : other->m_tables) {
591+
for (size_t i = 0; i < t_MAX; ++i) {
594592
//copy constructor will just connect to the already there table
595-
m_tables.push_back(std::shared_ptr<table_t>(new table_t(*t.get())));
593+
m_tables[i].reset(new table_t(*(other->m_tables[i].get())));
596594
}
597595
}
598596

output-pgsql.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "table.hpp"
1414
#include "tagtransform.hpp"
1515

16-
#include <vector>
16+
#include <array>
1717
#include <memory>
1818

1919
class output_pgsql_t : public output_t {
@@ -71,7 +71,7 @@ class output_pgsql_t : public output_t {
7171
//enable output of a generated way_area tag to either hstore or its own column
7272
int m_enable_way_area;
7373

74-
std::vector<std::shared_ptr<table_t> > m_tables;
74+
std::array<std::unique_ptr<table_t>, t_MAX> m_tables;
7575

7676
std::unique_ptr<export_list> m_export_list;
7777

0 commit comments

Comments
 (0)