Skip to content

Commit a0c4578

Browse files
committed
Avoid copying options inside output_t and access them through getter
The options were copied into output_t::m_options, that's not good because they are huge. Also this cleans up access to those options from derived classes only through the get_options() member function.
1 parent 51565f4 commit a0c4578

8 files changed

Lines changed: 62 additions & 56 deletions

File tree

src/output-flex.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,13 +1449,15 @@ void output_flex_t::stop()
14491449
{
14501450
for (auto &table : m_table_connections) {
14511451
table.task_set(thread_pool().submit([&]() {
1452-
table.stop(m_options.slim && !m_options.droptemp, m_options.append);
1452+
table.stop(get_options()->slim && !get_options()->droptemp,
1453+
get_options()->append);
14531454
}));
14541455
}
14551456

1456-
if (m_options.expire_tiles_zoom_min > 0) {
1457-
m_expire.output_and_destroy(m_options.expire_tiles_filename.c_str(),
1458-
m_options.expire_tiles_zoom_min);
1457+
if (get_options()->expire_tiles_zoom_min > 0) {
1458+
m_expire.output_and_destroy(
1459+
get_options()->expire_tiles_filename.c_str(),
1460+
get_options()->expire_tiles_zoom_min);
14591461
}
14601462
}
14611463

@@ -1572,16 +1574,16 @@ void output_flex_t::relation_modify(osmium::Relation const &rel)
15721574
void output_flex_t::init_clone()
15731575
{
15741576
for (auto &table : m_table_connections) {
1575-
table.connect(m_options.database_options.conninfo());
1577+
table.connect(get_options()->database_options.conninfo());
15761578
table.prepare();
15771579
}
15781580
}
15791581

15801582
void output_flex_t::start()
15811583
{
15821584
for (auto &table : m_table_connections) {
1583-
table.connect(m_options.database_options.conninfo());
1584-
table.start(m_options.append);
1585+
table.connect(get_options()->database_options.conninfo());
1586+
table.start(get_options()->append);
15851587
}
15861588
}
15871589

@@ -1618,7 +1620,7 @@ output_flex_t::output_flex_t(
16181620
assert(copy_thread);
16191621

16201622
if (!is_clone) {
1621-
init_lua(m_options.style);
1623+
init_lua(get_options()->style);
16221624

16231625
// If the osm2pgsql.select_relation_members() Lua function is defined
16241626
// it means we need two-stage processing which in turn means we need
@@ -1656,7 +1658,7 @@ void output_flex_t::init_lua(std::string const &filename)
16561658

16571659
luaX_add_table_str(lua_state(), "version", get_osm2pgsql_short_version());
16581660
luaX_add_table_str(lua_state(), "mode",
1659-
m_options.append ? "append" : "create");
1661+
get_options()->append ? "append" : "create");
16601662
luaX_add_table_int(lua_state(), "stage", 1);
16611663

16621664
std::string dir_path =
@@ -1755,7 +1757,7 @@ void output_flex_t::reprocess_marked()
17551757

17561758
log_info("Reprocess marked ways (stage 2)...");
17571759

1758-
if (!m_options.append) {
1760+
if (!get_options()->append) {
17591761
util::timer_t timer;
17601762

17611763
for (auto &table : m_table_connections) {

src/output-gazetteer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
void output_gazetteer_t::delete_unused_classes(char osm_type, osmid_t osm_id)
2525
{
26-
if (m_options.append) {
26+
if (get_options()->append) {
2727
m_copy.prepare();
2828

2929
assert(m_style.has_data());
@@ -35,7 +35,7 @@ void output_gazetteer_t::delete_unused_classes(char osm_type, osmid_t osm_id)
3535

3636
void output_gazetteer_t::delete_unused_full(char osm_type, osmid_t osm_id)
3737
{
38-
if (m_options.append) {
38+
if (get_options()->append) {
3939
m_copy.prepare();
4040
m_copy.delete_object(osm_type, osm_id);
4141
}
@@ -44,10 +44,10 @@ void output_gazetteer_t::delete_unused_full(char osm_type, osmid_t osm_id)
4444
void output_gazetteer_t::start()
4545
{
4646
/* (Re)create the table unless we are appending */
47-
if (!m_options.append) {
48-
int const srid = m_options.projection->target_srs();
47+
if (!get_options()->append) {
48+
int const srid = get_options()->projection->target_srs();
4949

50-
pg_conn_t conn{m_options.database_options.conninfo()};
50+
pg_conn_t conn{get_options()->database_options.conninfo()};
5151

5252
/* Drop any existing table */
5353
conn.exec("DROP TABLE IF EXISTS place CASCADE");
@@ -65,14 +65,14 @@ void output_gazetteer_t::start()
6565
" address hstore,"
6666
" extratags hstore," +
6767
" geometry Geometry(Geometry,{}) NOT NULL"_format(srid) + ")" +
68-
tablespace_clause(m_options.tblsmain_data);
68+
tablespace_clause(get_options()->tblsmain_data);
6969

7070
conn.exec(sql);
7171

7272
std::string const index_sql =
7373
"CREATE INDEX place_id_idx ON place"
7474
" USING BTREE (osm_type, osm_id)" +
75-
tablespace_clause(m_options.tblsmain_index);
75+
tablespace_clause(get_options()->tblsmain_index);
7676
conn.exec(index_sql);
7777
}
7878
}

src/output-gazetteer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class output_gazetteer_t : public output_t
3131
output_gazetteer_t(output_gazetteer_t const *other,
3232
std::shared_ptr<middle_query_t> const &cloned_mid,
3333
std::shared_ptr<db_copy_thread_t> const &copy_thread)
34-
: output_t(cloned_mid, other->m_thread_pool, other->m_options),
35-
m_copy(copy_thread), m_proj(other->m_options.projection),
34+
: output_t(cloned_mid, other->m_thread_pool, *other->get_options()),
35+
m_copy(copy_thread), m_proj(other->get_options()->projection),
3636
m_osmium_buffer(PLACE_BUFFER_SIZE, osmium::memory::Buffer::auto_grow::yes)
3737
{}
3838

src/output-null.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ std::shared_ptr<output_t>
1313
output_null_t::clone(std::shared_ptr<middle_query_t> const &mid,
1414
std::shared_ptr<db_copy_thread_t> const &) const
1515
{
16-
return std::make_shared<output_null_t>(mid, m_thread_pool, m_options);
16+
return std::make_shared<output_null_t>(mid, m_thread_pool, *get_options());
1717
}
1818

1919
output_null_t::output_null_t(std::shared_ptr<middle_query_t> const &mid,

src/output-pgsql.cpp

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ void output_pgsql_t::pgsql_out_way(osmium::Way const &way, taglist_t *tags,
6969
if (!wkb.empty()) {
7070
m_expire.from_geometry(projected_geom, way.id());
7171
if (m_enable_way_area) {
72-
double const area = calculate_area(m_options.reproject_area,
73-
geom, projected_geom);
72+
double const area = calculate_area(
73+
get_options()->reproject_area, geom, projected_geom);
7474
util::double_to_buffer tmp{area};
7575
tags->set("way_area", tmp.c_str());
7676
}
7777
m_tables[t_poly]->write_row(way.id(), *tags, wkb);
7878
}
7979
} else {
8080
double const split_at =
81-
m_options.projection->target_latlon() ? 1 : 100 * 1000;
81+
get_options()->projection->target_latlon() ? 1 : 100 * 1000;
8282
auto const geoms = geom::split_multi(geom::segmentize(
8383
geom::transform(geom::create_linestring(way), *m_proj), split_at));
8484
for (auto const &sgeom : geoms) {
@@ -139,14 +139,16 @@ void output_pgsql_t::stop()
139139
{
140140
for (auto &t : m_tables) {
141141
t->task_set(thread_pool().submit([&]() {
142-
t->stop(m_options.slim && !m_options.droptemp,
143-
m_options.enable_hstore_index, m_options.tblsmain_index);
142+
t->stop(get_options()->slim && !get_options()->droptemp,
143+
get_options()->enable_hstore_index,
144+
get_options()->tblsmain_index);
144145
}));
145146
}
146147

147-
if (m_options.expire_tiles_zoom_min > 0) {
148-
m_expire.output_and_destroy(m_options.expire_tiles_filename.c_str(),
149-
m_options.expire_tiles_zoom_min);
148+
if (get_options()->expire_tiles_zoom_min > 0) {
149+
m_expire.output_and_destroy(
150+
get_options()->expire_tiles_filename.c_str(),
151+
get_options()->expire_tiles_zoom_min);
150152
}
151153
}
152154

@@ -239,7 +241,7 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
239241
taglist_t outtags;
240242

241243
rolelist_t xrole;
242-
if (!m_options.tag_transform_script.empty()) {
244+
if (!get_options()->tag_transform_script.empty()) {
243245
xrole = get_rolelist(rel, m_buffer);
244246
}
245247

@@ -260,7 +262,7 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
260262
// for boundaries the way_area tag may be added.
261263
if (!make_polygon) {
262264
double const split_at =
263-
m_options.projection->target_latlon() ? 1 : 100 * 1000;
265+
get_options()->projection->target_latlon() ? 1 : 100 * 1000;
264266
auto geom = geom::line_merge(geom::create_multilinestring(m_buffer));
265267
auto projected_geom = geom::transform(geom, *m_proj);
266268
if (!projected_geom.is_null() && split_at > 0.0) {
@@ -279,15 +281,16 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
279281

280282
// multipolygons and boundaries
281283
if (make_boundary || make_polygon) {
282-
auto const geoms = geom::split_multi(
283-
geom::create_multipolygon(rel, m_buffer), !m_options.enable_multi);
284+
auto const geoms =
285+
geom::split_multi(geom::create_multipolygon(rel, m_buffer),
286+
!get_options()->enable_multi);
284287
for (auto const &sgeom : geoms) {
285288
auto const projected_geom = geom::transform(sgeom, *m_proj);
286289
m_expire.from_geometry(projected_geom, -rel.id());
287290
auto const wkb = geom_to_ewkb(projected_geom);
288291
if (m_enable_way_area) {
289-
double const area = calculate_area(m_options.reproject_area,
290-
sgeom, projected_geom);
292+
double const area = calculate_area(
293+
get_options()->reproject_area, sgeom, projected_geom);
291294
util::double_to_buffer tmp{area};
292295
outtags.set("way_area", tmp.c_str());
293296
}
@@ -329,11 +332,11 @@ void output_pgsql_t::node_delete(osmid_t osm_id)
329332
void output_pgsql_t::pgsql_delete_way_from_output(osmid_t osm_id)
330333
{
331334
/* Optimisation: we only need this is slim mode */
332-
if (!m_options.slim) {
335+
if (!get_options()->slim) {
333336
return;
334337
}
335338
/* in droptemp mode we don't have indices and this takes ages. */
336-
if (m_options.droptemp) {
339+
if (get_options()->droptemp) {
337340
return;
338341
}
339342

@@ -395,8 +398,8 @@ void output_pgsql_t::start()
395398
{
396399
for (auto &t : m_tables) {
397400
//setup the table in postgres
398-
t->start(m_options.database_options.conninfo(),
399-
m_options.tblsmain_data);
401+
t->start(get_options()->database_options.conninfo(),
402+
get_options()->tblsmain_data);
400403
}
401404
}
402405

@@ -422,9 +425,9 @@ output_pgsql_t::output_pgsql_t(
422425

423426
export_list exlist;
424427

425-
m_enable_way_area = read_style_file(m_options.style, &exlist);
428+
m_enable_way_area = read_style_file(get_options()->style, &exlist);
426429

427-
m_tagtransform = tagtransform_t::make_tagtransform(&m_options, exlist);
430+
m_tagtransform = tagtransform_t::make_tagtransform(get_options(), exlist);
428431

429432
//for each table
430433
for (size_t i = 0; i < t_MAX; ++i) {
@@ -434,7 +437,7 @@ output_pgsql_t::output_pgsql_t(
434437
(i == t_point) ? osmium::item_type::node : osmium::item_type::way);
435438

436439
//figure out what name we are using for this and what type
437-
std::string name = m_options.prefix;
440+
std::string name = get_options()->prefix;
438441
std::string type;
439442
switch (i) {
440443
case t_point:
@@ -459,20 +462,22 @@ output_pgsql_t::output_pgsql_t(
459462
}
460463

461464
m_tables[i] = std::make_unique<table_t>(
462-
name, type, columns, m_options.hstore_columns,
463-
m_options.projection->target_srs(), m_options.append,
464-
m_options.hstore_mode, copy_thread, m_options.output_dbschema);
465+
name, type, columns, get_options()->hstore_columns,
466+
get_options()->projection->target_srs(), get_options()->append,
467+
get_options()->hstore_mode, copy_thread,
468+
get_options()->output_dbschema);
465469
}
466470
}
467471

468472
output_pgsql_t::output_pgsql_t(
469473
output_pgsql_t const *other, std::shared_ptr<middle_query_t> const &mid,
470474
std::shared_ptr<db_copy_thread_t> const &copy_thread)
471-
: output_t(mid, other->m_thread_pool, other->m_options),
475+
: output_t(mid, other->m_thread_pool, *other->get_options()),
472476
m_tagtransform(other->m_tagtransform->clone()),
473-
m_enable_way_area(other->m_enable_way_area), m_proj(m_options.projection),
474-
m_expire(m_options.expire_tiles_zoom, m_options.expire_tiles_max_bbox,
475-
m_options.projection),
477+
m_enable_way_area(other->m_enable_way_area),
478+
m_proj(get_options()->projection),
479+
m_expire(get_options()->expire_tiles_zoom,
480+
get_options()->expire_tiles_max_bbox, get_options()->projection),
476481
m_buffer(1024, osmium::memory::Buffer::auto_grow::yes),
477482
m_rels_buffer(1024, osmium::memory::Buffer::auto_grow::yes)
478483
{

src/output.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ output_t::create_output(std::shared_ptr<middle_query_t> const &mid,
6666
output_t::output_t(std::shared_ptr<middle_query_t> mid,
6767
std::shared_ptr<thread_pool_t> thread_pool,
6868
options_t const &options)
69-
: m_mid(std::move(mid)), m_thread_pool(std::move(thread_pool)),
70-
m_options(options)
69+
: m_mid(std::move(mid)), m_options(&options),
70+
m_thread_pool(std::move(thread_pool))
71+
7172
{}
7273

7374
output_t::~output_t() = default;
@@ -77,6 +78,4 @@ void output_t::free_middle_references()
7778
m_mid.reset();
7879
}
7980

80-
options_t const *output_t::get_options() const { return &m_options; }
81-
8281
void output_t::merge_expire_trees(output_t *) {}

src/output.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ class output_t
8686
virtual void way_delete(osmid_t id) = 0;
8787
virtual void relation_delete(osmid_t id) = 0;
8888

89-
const options_t *get_options() const;
90-
9189
virtual void merge_expire_trees(output_t *other);
9290

9391
struct output_requirements const &get_requirements() const noexcept
@@ -97,6 +95,7 @@ class output_t
9795

9896
private:
9997
std::shared_ptr<middle_query_t> m_mid;
98+
options_t const *m_options;
10099

101100
protected:
102101
thread_pool_t &thread_pool() const noexcept
@@ -111,8 +110,9 @@ class output_t
111110
return *m_mid;
112111
}
113112

113+
const options_t *get_options() const noexcept { return m_options; };
114+
114115
std::shared_ptr<thread_pool_t> m_thread_pool;
115-
const options_t m_options;
116116
output_requirements m_output_requirements{};
117117
};
118118

tests/test-parse-osmium.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct counting_output_t : public output_null_t
8484
clone(std::shared_ptr<middle_query_t> const &,
8585
std::shared_ptr<db_copy_thread_t> const &) const override
8686
{
87-
return std::make_shared<counting_output_t>(m_options);
87+
return std::make_shared<counting_output_t>(*get_options());
8888
}
8989

9090
void node_add(osmium::Node const &n) override

0 commit comments

Comments
 (0)