Skip to content

Commit 66b7bd9

Browse files
authored
Merge pull request #1512 from joto/misc-cleanups
Misc cleanups
2 parents e1631b1 + 94c17af commit 66b7bd9

33 files changed

+129
-141
lines changed

src/db-check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Check whether the table with the specified name exists in the specified
1919
* schema in the database. Leave schema empty to check in the 'public' schema.
2020
*/
21-
static bool has_table(pg_conn_t &db_connection, std::string const &schema,
21+
static bool has_table(pg_conn_t const &db_connection, std::string const &schema,
2222
std::string const &table)
2323
{
2424
auto const sql = "SELECT count(*) FROM pg_tables"

src/db-copy-mgr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class db_copy_mgr_t
4141
m_processor->add_buffer(std::move(m_current));
4242
}
4343

44-
m_current.reset(new db_cmd_copy_delete_t<DELETER>{table});
44+
m_current = std::make_unique<db_cmd_copy_delete_t<DELETER>>(table);
4545
}
4646
}
4747

src/db-copy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ db_copy_thread_t::thread_t::thread_t(std::string conninfo, shared &shared)
124124
void db_copy_thread_t::thread_t::operator()()
125125
{
126126
try {
127-
m_conn.reset(new pg_conn_t{m_conninfo});
127+
m_conn = std::make_unique<pg_conn_t>(m_conninfo);
128128

129129
// Let commits happen faster by delaying when they actually occur.
130130
m_conn->exec("SET synchronous_commit = off");

src/expire-tiles.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void expire_tiles::expire_tile(uint32_t x, uint32_t y)
116116
}
117117
}
118118

119-
uint32_t expire_tiles::normalise_tile_x_coord(int x)
119+
uint32_t expire_tiles::normalise_tile_x_coord(int x) const
120120
{
121121
x %= map_width;
122122
if (x < 0) {
@@ -141,10 +141,10 @@ void expire_tiles::coords_to_tile(double lon, double lat, double *tilex,
141141
void expire_tiles::from_line(double lon_a, double lat_a, double lon_b,
142142
double lat_b)
143143
{
144-
double tile_x_a;
145-
double tile_y_a;
146-
double tile_x_b;
147-
double tile_y_b;
144+
double tile_x_a = NAN;
145+
double tile_y_a = NAN;
146+
double tile_x_b = NAN;
147+
double tile_y_b = NAN;
148148

149149
coords_to_tile(lon_a, lat_a, &tile_x_a, &tile_y_a);
150150
coords_to_tile(lon_b, lat_b, &tile_x_b, &tile_y_b);
@@ -237,8 +237,8 @@ int expire_tiles::from_bbox(double min_lon, double min_lat, double max_lon,
237237
}
238238

239239
/* Convert the box's Mercator coordinates into tile coordinates */
240-
double tmp_x;
241-
double tmp_y;
240+
double tmp_x = NAN;
241+
double tmp_y = NAN;
242242
coords_to_tile(min_lon, max_lat, &tmp_x, &tmp_y);
243243
int min_tile_x = tmp_x - TILE_EXPIRY_LEEWAY;
244244
int min_tile_y = tmp_y - TILE_EXPIRY_LEEWAY;

src/expire-tiles.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
class reprojection;
2121
class table_t;
2222
class tile;
23+
2324
namespace ewkb {
2425
class parser_t;
25-
}
26+
} // namespace ewkb
2627

2728
/**
2829
* \brief Simple struct for the x and y index of a tile ID.
@@ -114,11 +115,10 @@ struct expire_tiles
114115
* (larger than largest possible quadkey). */
115116
uint64_t last_quadkey = 1ULL << (2 * maxzoom);
116117
std::size_t count = 0;
117-
for (std::vector<uint64_t>::const_iterator it = tiles_maxzoom.cbegin();
118-
it != tiles_maxzoom.cend(); ++it) {
118+
for (auto const quadkey : tiles_maxzoom) {
119119
for (uint32_t dz = 0; dz <= maxzoom - minzoom; ++dz) {
120120
// scale down to the current zoom level
121-
uint64_t qt_current = *it >> (dz * 2);
121+
uint64_t qt_current = quadkey >> (dz * 2);
122122
/* If dz > 0, there are propably multiple elements whose quadkey
123123
* is equal because they are all sub-tiles of the same tile at the current
124124
* zoom level. We skip all of them after we have written the first sibling.
@@ -130,7 +130,7 @@ struct expire_tiles
130130
output_writer.output_dirty_tile(xy.x, xy.y, maxzoom - dz);
131131
++count;
132132
}
133-
last_quadkey = *it;
133+
last_quadkey = quadkey;
134134
}
135135
log_info("Wrote {} entries to expired tiles list", count);
136136
}
@@ -178,7 +178,7 @@ struct expire_tiles
178178
* \param y y index of the tile to be expired.
179179
*/
180180
void expire_tile(uint32_t x, uint32_t y);
181-
uint32_t normalise_tile_x_coord(int x);
181+
uint32_t normalise_tile_x_coord(int x) const;
182182
void from_line(double lon_a, double lat_a, double lon_b, double lat_b);
183183

184184
void from_wkb_point(ewkb::parser_t *wkb);

src/flex-table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void table_connection_t::connect(std::string const &conninfo)
152152
{
153153
assert(!m_db_connection);
154154

155-
m_db_connection.reset(new pg_conn_t{conninfo});
155+
m_db_connection = std::make_unique<pg_conn_t>(conninfo);
156156
m_db_connection->exec("SET synchronous_commit = off");
157157
}
158158

src/gazetteer-style.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@
2121
#include "pgsql.hpp"
2222
#include "wkb.hpp"
2323

24-
namespace {
25-
26-
enum : int
27-
{
28-
MAX_ADMINLEVEL = 15
29-
};
30-
31-
} // anonymous namespace
32-
3324
namespace pt = boost::property_tree;
3425

3526
void db_deleter_place_t::delete_rows(std::string const &table,

src/gazetteer-style.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ class gazetteer_copy_mgr_t : public db_copy_mgr_t<db_deleter_place_t>
9494
std::shared_ptr<db_target_descr_t> m_table;
9595
};
9696

97+
enum : int
98+
{
99+
MAX_ADMINLEVEL = 15
100+
};
101+
97102
class gazetteer_style_t
98103
{
99104
using flag_t = uint16_t;
@@ -179,7 +184,7 @@ class gazetteer_style_t
179184
/// value of operator tag
180185
char const *m_operator = nullptr;
181186
/// admin level
182-
int m_admin_level;
187+
int m_admin_level = MAX_ADMINLEVEL;
183188

184189
/// which metadata fields of the OSM objects should be written to the output
185190
osmium::metadata_options m_metadata_fields{"none"};

src/geom.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ void split_linestring(linestring_t const &line, double split_at,
9595
dist = 0;
9696
prev_pt = this_pt;
9797
continue;
98-
} else {
99-
dist = distance(this_pt, ipoint);
10098
}
99+
dist = distance(this_pt, ipoint);
101100
} else {
102101
dist += delta;
103102
}

src/geom.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class linestring_t
6969

7070
void add_point(osmium::geom::Coordinates coordinates)
7171
{
72-
m_coordinates.emplace_back(std::move(coordinates));
72+
m_coordinates.emplace_back(coordinates);
7373
}
7474

7575
iterator begin() noexcept { return m_coordinates.begin(); }

0 commit comments

Comments
 (0)