Skip to content

Commit 3f8a6b0

Browse files
authored
Merge pull request #1380 from joto/pointer-for-mutable-param
Use pointer for mutable parameters
2 parents 8d06d49 + 9103189 commit 3f8a6b0

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

src/input.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,13 @@ prepare_input_files(std::vector<std::string> const &input_files,
207207
class input_context_t
208208
{
209209
public:
210-
input_context_t(osmdata_t &osmdata, progress_display_t &progress,
210+
input_context_t(osmdata_t *osmdata, progress_display_t *progress,
211211
bool append)
212212
: m_osmdata(osmdata), m_progress(progress), m_append(append)
213-
{}
213+
{
214+
assert(osmdata);
215+
assert(progress);
216+
}
214217

215218
void apply(osmium::OSMObject &object)
216219
{
@@ -221,46 +224,46 @@ class input_context_t
221224

222225
if (m_last_type != object.type()) {
223226
if (m_last_type == osmium::item_type::node) {
224-
m_osmdata.after_nodes();
225-
m_progress.start_way_counter();
227+
m_osmdata->after_nodes();
228+
m_progress->start_way_counter();
226229
}
227230
if (object.type() == osmium::item_type::relation) {
228-
m_osmdata.after_ways();
229-
m_progress.start_relation_counter();
231+
m_osmdata->after_ways();
232+
m_progress->start_relation_counter();
230233
}
231234
m_last_type = object.type();
232235
}
233236

234-
osmium::apply_item(object, m_osmdata, m_progress);
237+
osmium::apply_item(object, *m_osmdata, *m_progress);
235238
}
236239

237240
void eof()
238241
{
239242
switch (m_last_type) {
240243
case osmium::item_type::node:
241-
m_osmdata.after_nodes();
244+
m_osmdata->after_nodes();
242245
// fallthrough
243246
case osmium::item_type::way:
244-
m_osmdata.after_ways();
247+
m_osmdata->after_ways();
245248
break;
246249
default:
247250
break;
248251
}
249252

250-
m_osmdata.after_relations();
251-
m_progress.print_summary();
253+
m_osmdata->after_relations();
254+
m_progress->print_summary();
252255
}
253256

254257
private:
255-
osmdata_t &m_osmdata;
256-
progress_display_t &m_progress;
258+
osmdata_t *m_osmdata;
259+
progress_display_t *m_progress;
257260
osmium::item_type m_last_type = osmium::item_type::node;
258261
bool m_append;
259262
}; // class input_context_t
260263

261264
static void process_single_file(osmium::io::File const &file,
262-
osmdata_t &osmdata,
263-
progress_display_t &progress, bool append)
265+
osmdata_t *osmdata,
266+
progress_display_t *progress, bool append)
264267
{
265268
osmium::io::Reader reader{file};
266269
type_id_version last{osmium::item_type::node, 0, 0};
@@ -278,8 +281,8 @@ static void process_single_file(osmium::io::File const &file,
278281
}
279282

280283
static void process_multiple_files(std::vector<osmium::io::File> const &files,
281-
osmdata_t &osmdata,
282-
progress_display_t &progress, bool append)
284+
osmdata_t *osmdata,
285+
progress_display_t *progress, bool append)
283286
{
284287
std::vector<data_source_t> data_sources;
285288
data_sources.reserve(files.size());
@@ -315,13 +318,15 @@ static void process_multiple_files(std::vector<osmium::io::File> const &files,
315318
}
316319

317320
void process_files(std::vector<osmium::io::File> const &files,
318-
osmdata_t &osmdata, bool append, bool show_progress)
321+
osmdata_t *osmdata, bool append, bool show_progress)
319322
{
323+
assert(osmdata);
324+
320325
progress_display_t progress{show_progress};
321326

322327
if (files.size() == 1) {
323-
process_single_file(files.front(), osmdata, progress, append);
328+
process_single_file(files.front(), osmdata, &progress, append);
324329
} else {
325-
process_multiple_files(files, osmdata, progress, append);
330+
process_multiple_files(files, osmdata, &progress, append);
326331
}
327332
}

src/input.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ prepare_input_files(std::vector<std::string> const &input_files,
4848
* Process the specified OSM files (stage 1a).
4949
*/
5050
void process_files(std::vector<osmium::io::File> const &files,
51-
osmdata_t &osmdata, bool append, bool show_progress);
51+
osmdata_t *osmdata, bool append, bool show_progress);
5252

5353
#endif // OSM2PGSQL_INPUT_HPP

src/osm2pgsql.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ static void run(options_t const &options)
6363

6464
// Processing: In this phase the input file(s) are read and parsed,
6565
// populating some of the tables.
66-
process_files(files, osmdata, options.append,
67-
get_logger().show_progress());
66+
process_files(files, &osmdata, options.append,
67+
get_logger().show_progress());
6868

6969
// Process pending ways and relations. Cluster database tables and
7070
// create indexes.

tests/common-import.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ inline void parse_file(options_t const &options,
4444
} else {
4545
filepath += options.input_files[0];
4646
}
47-
osmium::io::File file{filepath};
48-
process_files({file}, osmdata, options.append, false);
47+
osmium::io::File const file{filepath};
48+
process_files({file}, &osmdata, options.append, false);
4949

5050
if (do_stop) {
5151
osmdata.stop();
@@ -156,7 +156,7 @@ class import_t
156156
for (auto const &data : input_data) {
157157
files.emplace_back(data.data(), data.size(), format);
158158
}
159-
process_files(files, osmdata, options.append, false);
159+
process_files(files, &osmdata, options.append, false);
160160

161161
osmdata.stop();
162162
}

0 commit comments

Comments
 (0)