Skip to content

Commit 70954a0

Browse files
authored
codebase review and improvements
1 parent 9959b98 commit 70954a0

25 files changed

+109
-190
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
`3.12`. ([#686](https://github.com/odygrd/quill/issues/686))
215215
- Correct the installation location of pkg-config files. They are now properly placed in `/usr/local/lib`.
216216
([#715](https://github.com/odygrd/quill/issues/715))
217+
- Removed deprecated `TriviallyCopyableTypeCodec`
217218

218219
## v8.2.0
219220

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ set(HEADER_FILES
254254
include/quill/LogMacros.h
255255
include/quill/StopWatch.h
256256
include/quill/StringRef.h
257-
include/quill/TriviallyCopyableCodec.h
258257
include/quill/UserClockSource.h
259258
include/quill/Utility.h
260259
)

include/quill/Backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @page copyright
3-
* Copyright(c) 2020-present, Odysseas Georgoudis & quill contributors.* @page copyright
3+
* Copyright(c) 2020-present, Odysseas Georgoudis & quill contributors.
44
* Distributed under the MIT License (http://opensource.org/licenses/MIT)
55
*/
66

include/quill/CsvWriter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ class CsvWriter
183183
*/
184184
~CsvWriter()
185185
{
186-
_logger->flush_log();
187186
frontend_t::remove_logger(_logger);
188187
}
189188

include/quill/Logger.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,15 @@ class LoggerImpl : public detail::LoggerBase
115115
{
116116
current_timestamp = detail::get_timestamp_ns<std::chrono::system_clock>();
117117
}
118-
else
118+
else if (user_clock)
119119
{
120120
current_timestamp = user_clock->now();
121121
}
122+
else
123+
{
124+
// not expected
125+
current_timestamp = 0;
126+
}
122127

123128
if (QUILL_UNLIKELY(thread_context == nullptr))
124129
{
@@ -359,15 +364,7 @@ class LoggerImpl : public detail::LoggerBase
359364
*/
360365
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT std::byte* _prepare_write_buffer(size_t total_size)
361366
{
362-
if constexpr (using_unbounded_queue)
363-
{
364-
// MSVC doesn't like the template keyword, but every other compiler requires it
365-
return thread_context->get_spsc_queue<frontend_options_t::queue_type>().prepare_write(total_size);
366-
}
367-
else
368-
{
369-
return thread_context->get_spsc_queue<frontend_options_t::queue_type>().prepare_write(total_size);
370-
}
367+
return thread_context->get_spsc_queue<frontend_options_t::queue_type>().prepare_write(total_size);
371368
}
372369
};
373370

include/quill/StopWatch.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,7 @@ class StopWatch
7070
*/
7171
[[nodiscard]] std::chrono::duration<double> elapsed() const
7272
{
73-
if constexpr (ClockType == ClockSourceType::Tsc)
74-
{
75-
return std::chrono::duration<double>(std::chrono::nanoseconds{
76-
static_cast<uint64_t>(static_cast<double>(rdtsc() - _start_tp) * _ns_per_tick)});
77-
}
78-
else
79-
{
80-
return std::chrono::duration<double>(std::chrono::nanoseconds{
81-
detail::get_timestamp_ns<std::chrono::steady_clock>() - _start_tp});
82-
}
73+
return elapsed_as<std::chrono::duration<double>>();
8374
}
8475

8576
/**

include/quill/StringRef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class StringRef
3434
public:
3535
explicit StringRef(std::string const& str) : _str_view(str) {};
3636
explicit StringRef(std::string_view str) : _str_view(str) {};
37-
explicit StringRef(char const* str) : _str_view(str, strlen(str)) {};
37+
explicit StringRef(char const* str)
38+
: _str_view(str, detail::safe_strnlen(str, std::numeric_limits<uint32_t>::max())) {};
3839
StringRef(char const* str, size_t size) : _str_view(str, size) {};
3940

4041
QUILL_NODISCARD std::string_view const& get_string_view() const noexcept { return _str_view; }

include/quill/TriviallyCopyableCodec.h

Lines changed: 0 additions & 95 deletions
This file was deleted.

include/quill/UserClockSource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class UserClockSource
3333

3434
/**
3535
* Returns time since epoch in nanoseconds
36+
* @return The current timestamp in nanoseconds
3637
*/
3738
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT virtual uint64_t now() const = 0;
3839
};

include/quill/Utility.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,31 @@ namespace utility
2626
* @return A string containing the hexadecimal representation of the given buffer.
2727
*/
2828
template <typename T>
29-
QUILL_NODISCARD std::string to_hex(T* buffer, size_t size) noexcept
29+
QUILL_NODISCARD std::string to_hex(T const* buffer, size_t size)
3030
{
3131
static constexpr char hex_chars[] = "0123456789ABCDEF";
3232

33+
if (!buffer || size == 0)
34+
{
35+
return {};
36+
}
37+
38+
// Each byte needs 2 hex chars, and all but the last one need spaces
3339
std::string hex_string;
34-
hex_string.reserve(3 * size);
40+
hex_string.reserve(size > 0 ? (3 * size - 1) : 0);
3541

3642
for (size_t i = 0; i < size; ++i)
3743
{
38-
// 00001111 mask
39-
static constexpr uint8_t mask = 0x0Fu;
40-
41-
// add the first four bits
42-
hex_string += hex_chars[(buffer[i] >> 4u) & mask];
44+
const auto byte = static_cast<uint8_t>(buffer[i]);
4345

44-
// add the remaining bits
45-
hex_string += hex_chars[buffer[i] & mask];
46+
// Add the first four bits
47+
hex_string += hex_chars[(byte >> 4) & 0x0F];
48+
// Add the remaining bits
49+
hex_string += hex_chars[byte & 0x0F];
4650

51+
// Add a space delimiter after all but the last byte
4752
if (i != (size - 1))
4853
{
49-
// add a space delimiter
5054
hex_string += ' ';
5155
}
5256
}

include/quill/backend/BackendManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class BackendManager
9090
}
9191

9292
/***/
93-
QUILL_NODISCARD uint64_t convert_rdtsc_to_epoch_time(uint64_t rdtsc_value) const noexcept
93+
QUILL_NODISCARD uint64_t convert_rdtsc_to_epoch_time(uint64_t rdtsc_value) const
9494
{
9595
return _backend_worker.time_since_epoch(rdtsc_value);
9696
}

include/quill/backend/BackendWorker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class BackendWorker
9898
/***/
9999
QUILL_NODISCARD bool is_running() const noexcept
100100
{
101-
return _is_worker_running.load(std::memory_order_relaxed);
101+
return _is_worker_running.load(std::memory_order_acquire);
102102
}
103103

104104
/**
@@ -140,7 +140,7 @@ class BackendWorker
140140
}
141141

142142
std::thread worker(
143-
[this, &options]()
143+
[this, options]()
144144
{
145145
_init(options);
146146

include/quill/backend/StringFromTime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ class StringFromTime
378378
/***/
379379
QUILL_NODISCARD static time_t _nearest_quarter_hour_timestamp(time_t timestamp) noexcept
380380
{
381-
time_t const nearest_quarter_hour_ts = timestamp - (timestamp % 900);
381+
time_t const nearest_quarter_hour_ts = (timestamp / 900) * 900;
382382
return nearest_quarter_hour_ts;
383383
}
384384

include/quill/backend/TransitEventBuffer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class TransitEventBuffer
3232

3333
// Move constructor
3434
TransitEventBuffer(TransitEventBuffer&& other) noexcept
35-
: _capacity(other._capacity),
35+
: _initial_capacity(other._initial_capacity),
36+
_capacity(other._capacity),
3637
_storage(std::move(other._storage)),
3738
_mask(other._mask),
3839
_reader_pos(other._reader_pos),
@@ -49,6 +50,7 @@ class TransitEventBuffer
4950
{
5051
if (this != &other)
5152
{
53+
_initial_capacity = other._initial_capacity;
5254
_capacity = other._capacity;
5355
_storage = std::move(other._storage);
5456
_mask = other._mask;
@@ -152,4 +154,4 @@ class TransitEventBuffer
152154

153155
} // namespace detail
154156

155-
QUILL_END_NAMESPACE
157+
QUILL_END_NAMESPACE

0 commit comments

Comments
 (0)