Skip to content

Commit b845f26

Browse files
committed
minor improvements
1 parent 729acf6 commit b845f26

File tree

6 files changed

+17
-117
lines changed

6 files changed

+17
-117
lines changed

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/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ 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) : _str_view(str, str ? strlen(str) : 0) {};
3838
StringRef(char const* str, size_t size) : _str_view(str, size) {};
3939

4040
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
}

0 commit comments

Comments
 (0)