Skip to content

Commit 94c17af

Browse files
committed
Use std::make_shared/unique to reduce use of bare "new" operator
1 parent a00a8e2 commit 94c17af

File tree

11 files changed

+59
-76
lines changed

11 files changed

+59
-76
lines changed

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/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/input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class data_source_t
7474
{
7575
public:
7676
explicit data_source_t(osmium::io::File const &file)
77-
: m_reader(new osmium::io::Reader{file})
77+
: m_reader(std::make_unique<osmium::io::Reader>(file))
7878
{
7979
get_next_nonempty_buffer();
8080
m_last = check_input(m_last, *m_it);

src/middle-pgsql.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,16 +782,16 @@ static bool check_bucket_index(pg_conn_t *db_connection,
782782
middle_pgsql_t::middle_pgsql_t(std::shared_ptr<thread_pool_t> thread_pool,
783783
options_t const *options)
784784
: middle_t(std::move(thread_pool)), m_options(options),
785-
m_cache(new node_locations_t{static_cast<std::size_t>(options->cache) *
786-
1024UL * 1024UL}),
785+
m_cache(std::make_unique<node_locations_t>(
786+
static_cast<std::size_t>(options->cache) * 1024UL * 1024UL)),
787787
m_db_connection(m_options->database_options.conninfo()),
788788
m_copy_thread(
789789
std::make_shared<db_copy_thread_t>(options->database_options.conninfo())),
790790
m_db_copy(m_copy_thread)
791791
{
792792
if (!options->flat_node_file.empty()) {
793-
m_persistent_cache.reset(new node_persistent_cache{
794-
options->flat_node_file, options->droptemp});
793+
m_persistent_cache = std::make_shared<node_persistent_cache>(
794+
options->flat_node_file, options->droptemp);
795795
}
796796

797797
log_debug("Mid: pgsql, cache={}", options->cache);

src/node-persistent-cache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ node_persistent_cache::node_persistent_cache(std::string file_name,
4040
m_file_name, std::strerror(errno))};
4141
}
4242

43-
m_index.reset(new index_t{m_fd});
43+
m_index = std::make_unique<index_t>(m_fd);
4444
}
4545

4646
node_persistent_cache::~node_persistent_cache() noexcept

src/output-pgsql.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,10 @@ output_pgsql_t::output_pgsql_t(
437437
std::abort(); // should never be here
438438
}
439439

440-
m_tables[i].reset(
441-
new table_t{name, type, columns, m_options.hstore_columns,
442-
m_options.projection->target_srs(), m_options.append,
443-
m_options.hstore_mode, copy_thread,
444-
m_options.output_dbschema});
440+
m_tables[i] = std::make_unique<table_t>(
441+
name, type, columns, m_options.hstore_columns,
442+
m_options.projection->target_srs(), m_options.append,
443+
m_options.hstore_mode, copy_thread, m_options.output_dbschema);
445444
}
446445
}
447446

@@ -458,8 +457,8 @@ output_pgsql_t::output_pgsql_t(
458457
{
459458
for (size_t i = 0; i < t_MAX; ++i) {
460459
//copy constructor will just connect to the already there table
461-
m_tables[i].reset(
462-
new table_t{*(other->m_tables[i].get()), copy_thread});
460+
m_tables[i] =
461+
std::make_unique<table_t>(*(other->m_tables[i].get()), copy_thread);
463462
}
464463
}
465464

src/table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void table_t::sync() { m_copy.sync(); }
6868

6969
void table_t::connect()
7070
{
71-
m_sql_conn.reset(new pg_conn_t{m_conninfo});
71+
m_sql_conn = std::make_unique<pg_conn_t>(m_conninfo);
7272
//let commits happen faster by delaying when they actually occur
7373
m_sql_conn->exec("SET synchronous_commit = off");
7474
}

tests/common-import.hpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,7 @@ class import_t
137137
options.database_options = m_db.db_options();
138138

139139
auto thread_pool = std::make_shared<thread_pool_t>(1U);
140-
std::shared_ptr<middle_t> middle;
141-
142-
if (options.slim) {
143-
middle = std::shared_ptr<middle_t>(
144-
new middle_pgsql_t{thread_pool, &options});
145-
} else {
146-
middle = std::shared_ptr<middle_t>(
147-
new middle_ram_t{thread_pool, &options});
148-
}
140+
auto middle = create_middle(thread_pool, options);
149141
middle->start();
150142

151143
auto output = output_t::create_output(middle->get_query_instance(),

tests/test-middle.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
111111
}
112112

113113
auto thread_pool = std::make_shared<thread_pool_t>(1U);
114-
auto mid = options.slim ? std::shared_ptr<middle_t>(
115-
new middle_pgsql_t{thread_pool, &options})
116-
: std::shared_ptr<middle_t>(
117-
new middle_ram_t{thread_pool, &options});
118-
114+
auto mid = create_middle(thread_pool, options);
119115
mid->start();
120116

121117
output_requirements requirements;

0 commit comments

Comments
 (0)