Skip to content

Commit d4a7b37

Browse files
committed
Refactor osmdata_t code
Remove has_pending() which checks two things we can easily check each by itself and sometimes only need one or the other. Turn get_pending_way_ids() and get_pending_relation_ids() into simple getters, they are only needed for testing outside the class.
1 parent 89f4b0b commit d4a7b37

File tree

3 files changed

+42
-49
lines changed

3 files changed

+42
-49
lines changed

src/osmdata.cpp

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,15 @@ void osmdata_t::process_dependents()
383383
m_num_procs};
384384

385385
// stage 1b processing: process parents of changed objects
386-
if (has_pending()) {
387-
proc.process_ways(get_pending_way_ids());
388-
proc.process_relations(get_pending_relation_ids());
386+
if (!m_ways_pending_tracker.empty() || !m_rels_pending_tracker.empty()) {
387+
if (!m_ways_pending_tracker.empty()) {
388+
m_ways_pending_tracker.sort_unique();
389+
proc.process_ways(std::move(m_ways_pending_tracker));
390+
}
391+
if (!m_rels_pending_tracker.empty()) {
392+
m_rels_pending_tracker.sort_unique();
393+
proc.process_relations(std::move(m_rels_pending_tracker));
394+
}
389395
proc.merge_expire_trees();
390396
}
391397

@@ -395,14 +401,16 @@ void osmdata_t::process_dependents()
395401
return;
396402
}
397403

398-
assert(m_rels_pending_tracker.empty());
399-
m_mid->get_way_parents(marked_ways, &m_rels_pending_tracker);
400-
401404
// process parent relations of marked ways
402-
if (has_pending()) {
403-
proc.process_relations_stage1c(
404-
get_pending_relation_ids());
405+
idlist_t rels_pending_tracker{};
406+
m_mid->get_way_parents(marked_ways, &rels_pending_tracker);
407+
408+
if (rels_pending_tracker.empty()) {
409+
return;
405410
}
411+
412+
rels_pending_tracker.sort_unique();
413+
proc.process_relations_stage1c(std::move(rels_pending_tracker));
406414
}
407415

408416
void osmdata_t::reprocess_marked() const { m_output->reprocess_marked(); }
@@ -442,26 +450,3 @@ void osmdata_t::stop()
442450

443451
postprocess_database();
444452
}
445-
446-
bool osmdata_t::has_pending() const noexcept
447-
{
448-
return !m_ways_pending_tracker.empty() || !m_rels_pending_tracker.empty();
449-
}
450-
451-
idlist_t osmdata_t::get_pending_way_ids()
452-
{
453-
idlist_t list;
454-
using std::swap;
455-
swap(list, m_ways_pending_tracker);
456-
list.sort_unique();
457-
return list;
458-
}
459-
460-
idlist_t osmdata_t::get_pending_relation_ids()
461-
{
462-
idlist_t list;
463-
using std::swap;
464-
swap(list, m_rels_pending_tracker);
465-
list.sort_unique();
466-
return list;
467-
}

src/osmdata.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ class osmdata_t : public osmium::handler::Handler
5858
*/
5959
void stop();
6060

61-
bool has_pending() const noexcept;
62-
63-
idlist_t get_pending_way_ids();
64-
65-
idlist_t get_pending_relation_ids();
61+
// These getters are needed only for tests
62+
idlist_t const &get_pending_way_ids() const noexcept
63+
{
64+
return m_ways_pending_tracker;
65+
}
66+
67+
idlist_t const &get_pending_relation_ids() const noexcept
68+
{
69+
return m_rels_pending_tracker;
70+
}
6671

6772
private:
6873
/**

tests/test-middle.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,8 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
10651065
check_way(mid, way21);
10661066
check_way_nodes(mid, way21.id(), {&node11, &node12});
10671067

1068-
REQUIRE_FALSE(osmdata.has_pending());
1068+
REQUIRE(osmdata.get_pending_way_ids().empty());
1069+
REQUIRE(osmdata.get_pending_relation_ids().empty());
10691070

10701071
osmdata.stop();
10711072
}
@@ -1088,10 +1089,11 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
10881089
osmdata.after_ways();
10891090
osmdata.after_relations();
10901091

1091-
REQUIRE(osmdata.has_pending());
1092-
idlist_t const way_ids = osmdata.get_pending_way_ids();
1092+
idlist_t const &way_ids = osmdata.get_pending_way_ids();
10931093
REQUIRE(way_ids == idlist_t{20});
10941094

1095+
REQUIRE(osmdata.get_pending_relation_ids().empty());
1096+
10951097
check_way(mid, way20);
10961098
check_way_nodes(mid, way20.id(), {&node10a, &node11});
10971099
}
@@ -1123,10 +1125,11 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11231125
osmdata.after_ways();
11241126
osmdata.after_relations();
11251127

1126-
REQUIRE(osmdata.has_pending());
1127-
idlist_t const way_ids = osmdata.get_pending_way_ids();
1128+
idlist_t const &way_ids = osmdata.get_pending_way_ids();
11281129
REQUIRE(way_ids == idlist_t{20, 22});
11291130

1131+
REQUIRE(osmdata.get_pending_relation_ids().empty());
1132+
11301133
check_way(mid, way20);
11311134
check_way_nodes(mid, way20.id(), {&node10a, &node11});
11321135
check_way(mid, way22);
@@ -1168,7 +1171,8 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11681171
osmdata.after_ways();
11691172
osmdata.after_relations();
11701173

1171-
REQUIRE_FALSE(osmdata.has_pending());
1174+
REQUIRE(osmdata.get_pending_way_ids().empty());
1175+
REQUIRE(osmdata.get_pending_relation_ids().empty());
11721176
}
11731177
}
11741178
}
@@ -1237,10 +1241,10 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12371241
osmdata.after_ways();
12381242
osmdata.after_relations();
12391243

1240-
REQUIRE(osmdata.has_pending());
1241-
idlist_t const rel_ids = osmdata.get_pending_relation_ids();
1242-
1244+
REQUIRE(osmdata.get_pending_way_ids().empty());
1245+
idlist_t const &rel_ids = osmdata.get_pending_relation_ids();
12431246
REQUIRE(rel_ids == idlist_t{30});
1247+
12441248
check_relation(mid, rel30);
12451249
}
12461250

@@ -1259,10 +1263,9 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12591263
osmdata.after_ways();
12601264
osmdata.after_relations();
12611265

1262-
REQUIRE(osmdata.has_pending());
1263-
idlist_t const way_ids = osmdata.get_pending_way_ids();
1266+
idlist_t const &way_ids = osmdata.get_pending_way_ids();
12641267
REQUIRE(way_ids == idlist_t{20});
1265-
idlist_t const rel_ids = osmdata.get_pending_relation_ids();
1268+
idlist_t const &rel_ids = osmdata.get_pending_relation_ids();
12661269
REQUIRE(rel_ids == idlist_t{31});
12671270
check_relation(mid, rel31);
12681271
}

0 commit comments

Comments
 (0)