Skip to content

Commit 71d9d36

Browse files
authored
Merge pull request #2337 from joto/constants
Use UPPERCASE for constants
2 parents 812ba2f + 4a0243f commit 71d9d36

25 files changed

+128
-126
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Code must be written in the
3636
always be used for code blocks, even one-liners.
3737

3838
Names should use underscores, not camel case, with class/struct names ending in
39-
`_t`. Template parameters must use all upper case.
39+
`_t`. Constants and template parameters must use all upper case.
4040

4141
Header files should be included in the following order, each group in their own
4242
block:

src/db-copy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void db_copy_thread_t::send_command(db_cmd_t &&buffer)
100100

101101
std::unique_lock<std::mutex> lock{m_shared.queue_mutex};
102102
m_shared.queue_full_cond.wait(lock, [&] {
103-
return m_shared.worker_queue.size() < db_cmd_copy_t::Max_buffers;
103+
return m_shared.worker_queue.size() < db_cmd_copy_t::MAX_BUFFERS;
104104
});
105105

106106
m_shared.worker_queue.push_back(std::move(buffer));

src/db-copy.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class db_deleter_by_id_t
7979
* There is a trade-off here between sending as few DELETE SQL as
8080
* possible and keeping the size of the deletable vector managable.
8181
*/
82-
static constexpr std::size_t Max_entries = 1000000;
82+
static constexpr std::size_t MAX_ENTRIES = 1000000;
8383

8484
public:
8585
bool has_data() const noexcept { return !m_deletables.empty(); }
@@ -89,7 +89,7 @@ class db_deleter_by_id_t
8989
void delete_rows(std::string const &table, std::string const &column,
9090
pg_conn_t const &db_connection);
9191

92-
bool is_full() const noexcept { return m_deletables.size() > Max_entries; }
92+
bool is_full() const noexcept { return m_deletables.size() > MAX_ENTRIES; }
9393

9494
private:
9595
/// Vector with object to delete before copying
@@ -105,7 +105,7 @@ class db_deleter_by_type_and_id_t
105105
* There is a trade-off here between sending as few DELETE SQL as
106106
* possible and keeping the size of the deletable vector managable.
107107
*/
108-
static constexpr std::size_t Max_entries = 1000000;
108+
static constexpr std::size_t MAX_ENTRIES = 1000000;
109109

110110
struct item_t
111111
{
@@ -129,7 +129,7 @@ class db_deleter_by_type_and_id_t
129129
void delete_rows(std::string const &table, std::string const &column,
130130
pg_conn_t const &db_connection);
131131

132-
bool is_full() const noexcept { return m_deletables.size() > Max_entries; }
132+
bool is_full() const noexcept { return m_deletables.size() > MAX_ENTRIES; }
133133

134134
private:
135135
/// Vector with object to delete before copying
@@ -145,7 +145,7 @@ struct db_cmd_copy_t
145145
* to speed up processing. Currently a one-size fits all value.
146146
* Needs more testing and individual values per queue.
147147
*/
148-
static constexpr std::size_t Max_buf_size = 10 * 1024 * 1024;
148+
static constexpr std::size_t MAX_BUF_SIZE = 10UL * 1024UL * 1024UL;
149149

150150
/**
151151
* Maximum length of the queue with COPY data.
@@ -155,7 +155,7 @@ struct db_cmd_copy_t
155155
* be full and it is better to keep the queue smaller to reduce memory
156156
* usage. Current value is just assumed to be a reasonable trade off.
157157
*/
158-
static constexpr std::size_t Max_buffers = 10;
158+
static constexpr std::size_t MAX_BUFFERS = 10;
159159

160160
/// Name of the target table for the copy operation
161161
std::shared_ptr<db_target_descr_t> target;
@@ -167,7 +167,7 @@ struct db_cmd_copy_t
167167
explicit db_cmd_copy_t(std::shared_ptr<db_target_descr_t> t)
168168
: target(std::move(t))
169169
{
170-
buffer.reserve(Max_buf_size);
170+
buffer.reserve(MAX_BUF_SIZE);
171171
}
172172

173173
explicit operator bool() const noexcept { return target != nullptr; }
@@ -182,7 +182,7 @@ class db_cmd_copy_delete_t : public db_cmd_copy_t
182182
/// Return true if the buffer is filled up.
183183
bool is_full() const noexcept
184184
{
185-
return (buffer.size() > Max_buf_size - 100) || m_deleter.is_full();
185+
return (buffer.size() > MAX_BUF_SIZE - 100) || m_deleter.is_full();
186186
}
187187

188188
bool has_deletables() const noexcept { return m_deleter.has_data(); }

src/expire-tiles.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ geom::point_t expire_tiles::coords_to_tile(geom::point_t const &point)
6363
{
6464
auto const c = m_projection->target_to_tile(point);
6565

66-
return {m_map_width * (0.5 + c.x() / tile_t::earth_circumference),
67-
m_map_width * (0.5 - c.y() / tile_t::earth_circumference)};
66+
return {m_map_width * (0.5 + c.x() / tile_t::EARTH_CIRCUMFERENCE),
67+
m_map_width * (0.5 - c.y() / tile_t::EARTH_CIRCUMFERENCE)};
6868
}
6969

7070
void expire_tiles::from_point_list(geom::point_list_t const &list,
@@ -224,14 +224,14 @@ int expire_tiles::from_bbox(geom::box_t const &box,
224224

225225
double const width = box.width();
226226
double const height = box.height();
227-
if (width > tile_t::half_earth_circumference + 1) {
227+
if (width > tile_t::HALF_EARTH_CIRCUMFERENCE + 1) {
228228
/* Over half the planet's width within the bounding box - assume the
229229
box crosses the international date line and split it into two boxes */
230-
int ret = from_bbox({-tile_t::half_earth_circumference, box.min_y(),
230+
int ret = from_bbox({-tile_t::HALF_EARTH_CIRCUMFERENCE, box.min_y(),
231231
box.min_x(), box.max_y()},
232232
expire_config);
233233
ret += from_bbox({box.max_x(), box.min_y(),
234-
tile_t::half_earth_circumference, box.max_y()},
234+
tile_t::HALF_EARTH_CIRCUMFERENCE, box.max_y()},
235235
expire_config);
236236
return ret;
237237
}

src/gen/osm2pgsql-gen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
namespace {
7878

79-
constexpr std::size_t const max_force_single_thread = 4;
79+
constexpr std::size_t const MAX_FORCE_SINGLE_THREAD = 4;
8080

8181
struct tile_extent
8282
{
@@ -496,7 +496,7 @@ class genproc_t
496496
}
497497
}
498498
log_debug("Need to process {} tiles.", tile_list.size());
499-
if (m_jobs == 1 || tile_list.size() < max_force_single_thread) {
499+
if (m_jobs == 1 || tile_list.size() < MAX_FORCE_SINGLE_THREAD) {
500500
log_debug("Running in single-threaded mode.");
501501
tile_processor_t tp{generalizer, tile_list.size()};
502502
while (!tile_list.empty()) {

src/gen/tracer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ tracer_t::trace(canvas_t const &canvas, tile_t const &tile, double min_area)
4242
prepare(canvas);
4343

4444
potrace_bitmap_t const bitmap{int(canvas.size()), int(canvas.size()),
45-
int(canvas.size() / bits_per_word),
45+
int(canvas.size() / BITS_PER_WORD),
4646
m_bits.data()};
4747

4848
std::unique_ptr<potrace_state_t, potrace_state_deleter> state{
@@ -64,9 +64,9 @@ void tracer_t::reset()
6464
void tracer_t::prepare(canvas_t const &canvas) noexcept
6565
{
6666
std::size_t const size = canvas.size();
67-
assert(size % bits_per_word == 0);
67+
assert(size % BITS_PER_WORD == 0);
6868

69-
m_bits.reserve((size * size) / bits_per_word);
69+
m_bits.reserve((size * size) / BITS_PER_WORD);
7070

7171
for (unsigned char const *d = canvas.begin(); d != canvas.end(); d += 8) {
7272
auto w = bit_squeeze(0, d);

src/gen/tracer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class tracer_t
3939
std::size_t num_points() const noexcept { return m_num_points; }
4040

4141
private:
42-
static constexpr auto const bits_per_word = sizeof(potrace_word) * 8;
42+
static constexpr auto const BITS_PER_WORD = sizeof(potrace_word) * 8;
4343

4444
geom::point_t make_point(potrace_dpoint_t const &p) const noexcept;
4545

src/geom.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ class multigeometry_t
198198
using iterator = typename std::vector<GEOM>::iterator;
199199
using value_type = GEOM;
200200

201-
static constexpr bool const for_point = std::is_same_v<GEOM, point_t>;
201+
static constexpr bool const FOR_POINT = std::is_same_v<GEOM, point_t>;
202202

203203
[[nodiscard]] std::size_t num_geometries() const noexcept
204204
{
205205
return m_geometry.size();
206206
}
207207

208208
GEOM &
209-
add_geometry(typename std::conditional_t<for_point, point_t, GEOM &&> geom)
209+
add_geometry(typename std::conditional_t<FOR_POINT, point_t, GEOM &&> geom)
210210
{
211211
m_geometry.push_back(std::forward<GEOM>(geom));
212212
return m_geometry.back();

src/lua-utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ void *luaX_get_context(lua_State *lua_state) noexcept
3636
namespace {
3737

3838
// Unique key for lua registry
39-
constexpr char const *const osm2pgsql_output_flex = "osm2pgsql_output_flex";
39+
constexpr char const *const OSM2PGSQL_OUTPUT_FLEX = "osm2pgsql_output_flex";
4040

4141
} // anonymous namespace
4242

4343
void luaX_set_context(lua_State *lua_state, void *ptr) noexcept
4444
{
4545
assert(lua_state);
4646
assert(ptr);
47-
lua_pushlightuserdata(lua_state, (void *)osm2pgsql_output_flex);
47+
lua_pushlightuserdata(lua_state, (void *)OSM2PGSQL_OUTPUT_FLEX);
4848
lua_pushlightuserdata(lua_state, ptr);
4949
lua_settable(lua_state, LUA_REGISTRYINDEX);
5050
}
5151

5252
void *luaX_get_context(lua_State *lua_state) noexcept
5353
{
5454
assert(lua_state);
55-
lua_pushlightuserdata(lua_state, (void *)osm2pgsql_output_flex);
55+
lua_pushlightuserdata(lua_state, (void *)OSM2PGSQL_OUTPUT_FLEX);
5656
lua_gettable(lua_state, LUA_REGISTRYINDEX);
5757
auto *const ptr = lua_touserdata(lua_state, -1);
5858
assert(ptr);

src/node-locations.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ osmium::Location node_locations_t::get(osmid_t id) const
6464
osmium::DeltaDecode<int64_t> dx;
6565
osmium::DeltaDecode<int64_t> dy;
6666

67-
for (std::size_t n = 0; n < block_size && begin != end; ++n) {
67+
for (std::size_t n = 0; n < BLOCK_SIZE && begin != end; ++n) {
6868
auto const bid = did.update(
6969
static_cast<int64_t>(protozero::decode_varint(&begin, end)));
7070
auto const x = static_cast<int32_t>(dx.update(
@@ -83,13 +83,13 @@ osmium::Location node_locations_t::get(osmid_t id) const
8383

8484
void node_locations_t::log_stats()
8585
{
86-
constexpr auto const mbyte = 1024 * 1024;
86+
constexpr auto const MBYTE = 1024 * 1024;
8787
log_debug("Node locations cache:");
8888
log_debug(" num locations stored: {}", m_count);
89-
log_debug(" bytes overall: {}MB", used_memory() / mbyte);
90-
log_debug(" data capacity: {}MB", m_data.capacity() / mbyte);
91-
log_debug(" data size: {}MB", m_data.size() / mbyte);
92-
log_debug(" index used memory: {}MB", m_index.used_memory() / mbyte);
89+
log_debug(" bytes overall: {}MB", used_memory() / MBYTE);
90+
log_debug(" data capacity: {}MB", m_data.capacity() / MBYTE);
91+
log_debug(" data size: {}MB", m_data.size() / MBYTE);
92+
log_debug(" index used memory: {}MB", m_index.used_memory() / MBYTE);
9393
}
9494

9595
void node_locations_t::clear()

0 commit comments

Comments
 (0)