Skip to content

Commit ebe1b9d

Browse files
committed
Various code cleanups
Various code cleanups based on issues found by clang-tidy.
1 parent f2a866c commit ebe1b9d

20 files changed

Lines changed: 68 additions & 70 deletions

src/db-check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static bool has_table(pg_conn_t &db_connection, std::string const &schema,
1616
" WHERE schemaname='{}' AND tablename='{}'"_format(
1717
schema.empty() ? "public" : schema, table);
1818
auto const res = db_connection.query(PGRES_TUPLES_OK, sql);
19-
auto const num = res.get_value(0, 0);
19+
char const *const num = res.get_value(0, 0);
2020

2121
return num[0] == '1' && num[1] == '\0';
2222
}

src/db-copy-mgr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class db_copy_mgr_t
2727
*/
2828
void new_line(std::shared_ptr<db_target_descr_t> const &table)
2929
{
30-
if (!m_current || !m_current->target->same_copy_target(*table.get())) {
30+
if (!m_current || !m_current->target->same_copy_target(*table)) {
3131
if (m_current) {
3232
m_processor->add_buffer(std::move(m_current));
3333
}

src/db-copy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void db_copy_thread_t::thread_t::operator()()
160160
void db_copy_thread_t::thread_t::write_to_db(db_cmd_copy_t *buffer)
161161
{
162162
if (buffer->has_deletables() ||
163-
(m_inflight && !buffer->target->same_copy_target(*m_inflight.get()))) {
163+
(m_inflight && !buffer->target->same_copy_target(*m_inflight))) {
164164
finish_copy();
165165
}
166166

src/expire-tiles.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ class parser_t;
2020
*/
2121
struct xy_coord_t
2222
{
23-
uint32_t x;
24-
uint32_t y;
25-
xy_coord_t() : x(0), y(0) {}
23+
uint32_t x = 0;
24+
uint32_t y = 0;
2625
};
2726

2827
/**
@@ -33,7 +32,7 @@ class tile_output_t
3332
FILE *outfile;
3433

3534
public:
36-
tile_output_t(char const *filename);
35+
explicit tile_output_t(char const *filename);
3736

3837
~tile_output_t();
3938

src/flex-table-column.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ struct column_type_lookup
1313
table_column_type type;
1414
};
1515

16-
static column_type_lookup const column_types[] = {
17-
{"sql", table_column_type::sql},
18-
{"text", table_column_type::text},
19-
{"boolean", table_column_type::boolean},
20-
{"bool", table_column_type::boolean},
21-
{"int2", table_column_type::int2},
22-
{"smallint", table_column_type::int2},
23-
{"int4", table_column_type::int4},
24-
{"int", table_column_type::int4},
25-
{"integer", table_column_type::int4},
26-
{"int8", table_column_type::int8},
27-
{"bigint", table_column_type::int8},
28-
{"real", table_column_type::real},
29-
{"hstore", table_column_type::hstore},
30-
{"direction", table_column_type::direction},
31-
{"geometry", table_column_type::geometry},
32-
{"point", table_column_type::point},
33-
{"linestring", table_column_type::linestring},
34-
{"polygon", table_column_type::polygon},
35-
{"multipoint", table_column_type::multipoint},
36-
{"multilinestring", table_column_type::multilinestring},
37-
{"multipolygon", table_column_type::multipolygon},
38-
{"area", table_column_type::area},
39-
{"id_type", table_column_type::id_type},
40-
{"id_num", table_column_type::id_num}};
16+
static std::array<column_type_lookup, 24> const column_types = {
17+
{{"sql", table_column_type::sql},
18+
{"text", table_column_type::text},
19+
{"boolean", table_column_type::boolean},
20+
{"bool", table_column_type::boolean},
21+
{"int2", table_column_type::int2},
22+
{"smallint", table_column_type::int2},
23+
{"int4", table_column_type::int4},
24+
{"int", table_column_type::int4},
25+
{"integer", table_column_type::int4},
26+
{"int8", table_column_type::int8},
27+
{"bigint", table_column_type::int8},
28+
{"real", table_column_type::real},
29+
{"hstore", table_column_type::hstore},
30+
{"direction", table_column_type::direction},
31+
{"geometry", table_column_type::geometry},
32+
{"point", table_column_type::point},
33+
{"linestring", table_column_type::linestring},
34+
{"polygon", table_column_type::polygon},
35+
{"multipoint", table_column_type::multipoint},
36+
{"multilinestring", table_column_type::multilinestring},
37+
{"multipolygon", table_column_type::multipolygon},
38+
{"area", table_column_type::area},
39+
{"id_type", table_column_type::id_type},
40+
{"id_num", table_column_type::id_num}}};
4141

4242
static table_column_type
4343
get_column_type_from_string(std::string const &type) noexcept

src/flex-table.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class flex_table_t
3232
permanent
3333
};
3434

35-
flex_table_t(std::string name) : m_name(std::move(name)) {}
35+
explicit flex_table_t(std::string name) : m_name(std::move(name)) {}
3636

3737
std::string const &name() const noexcept { return m_name; }
3838

src/gazetteer-style.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void gazetteer_style_t::process_tags(osmium::OSMObject const &o)
290290
bool has_postcode = false;
291291
bool has_country = false;
292292
char const *place = nullptr;
293-
flag_t place_flag;
293+
flag_t place_flag = 0;
294294
bool address_point = false;
295295
bool interpolation = false;
296296
bool admin_boundary = false;
@@ -340,7 +340,7 @@ void gazetteer_style_t::process_tags(osmium::OSMObject const &o)
340340
}
341341

342342
if (flag & SF_ADDRESS) {
343-
char const *addr_key;
343+
char const *addr_key = nullptr;
344344
if (std::strncmp(k, "addr:", 5) == 0) {
345345
addr_key = k + 5;
346346
} else if (std::strncmp(k, "is_in:", 6) == 0) {

src/geom-transform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bool geom_transform_area_t::set_param(char const *name, lua_State *lua_state)
8282
return false;
8383
}
8484

85-
auto const val = lua_tostring(lua_state, -1);
85+
char const *const val = lua_tostring(lua_state, -1);
8686

8787
if (!val) {
8888
throw std::runtime_error{

src/middle-pgsql.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void pgsql_parse_members(char const *string, osmium::memory::Buffer &buffer,
180180

181181
while (*string != '}') {
182182
char type = string[0];
183-
char *endp;
183+
char *endp = nullptr;
184184
osmid_t id = std::strtoll(string + 1, &endp, 10);
185185
// String points to the comma */
186186
string = decode_upto(endp + 1, role);
@@ -198,7 +198,7 @@ void pgsql_parse_nodes(char const *string, osmium::memory::Buffer &buffer,
198198
if (*string++ == '{') {
199199
osmium::builder::WayNodeListBuilder wnl_builder{buffer, &builder};
200200
while (*string != '}') {
201-
char *ptr;
201+
char *ptr = nullptr;
202202
wnl_builder.add_node_ref(std::strtoll(string, &ptr, 10));
203203
string = ptr;
204204
if (*string == ',') {

src/middle-pgsql.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct table_sql {
5454

5555
struct middle_pgsql_t : public slim_middle_t
5656
{
57-
middle_pgsql_t(options_t const *options);
57+
explicit middle_pgsql_t(options_t const *options);
5858

5959
void start() override;
6060
void stop(thread_pool_t &pool) override;
@@ -79,7 +79,7 @@ struct middle_pgsql_t : public slim_middle_t
7979
class table_desc
8080
{
8181
public:
82-
table_desc() {}
82+
table_desc() = default;
8383
table_desc(options_t const &options, table_sql const &ts);
8484

8585
char const *name() const { return m_copy_target->name.c_str(); }

0 commit comments

Comments
 (0)