File tree Expand file tree Collapse file tree 6 files changed +17
-117
lines changed Expand file tree Collapse file tree 6 files changed +17
-117
lines changed Original file line number Diff line number Diff line change @@ -254,7 +254,6 @@ set(HEADER_FILES
254
254
include /quill/LogMacros.h
255
255
include /quill/StopWatch.h
256
256
include /quill/StringRef.h
257
- include /quill/TriviallyCopyableCodec.h
258
257
include /quill/UserClockSource.h
259
258
include /quill/Utility.h
260
259
)
Original file line number Diff line number Diff line change @@ -70,16 +70,7 @@ class StopWatch
70
70
*/
71
71
[[nodiscard]] std::chrono::duration<double > elapsed () const
72
72
{
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 >>();
83
74
}
84
75
85
76
/* *
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ class StringRef
34
34
public:
35
35
explicit StringRef (std::string const & str) : _str_view(str) {};
36
36
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 ) {};
38
38
StringRef (char const * str, size_t size) : _str_view(str, size) {};
39
39
40
40
QUILL_NODISCARD std::string_view const & get_string_view () const noexcept { return _str_view; }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ class UserClockSource
33
33
34
34
/* *
35
35
* Returns time since epoch in nanoseconds
36
+ * @return The current timestamp in nanoseconds
36
37
*/
37
38
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT virtual uint64_t now () const = 0;
38
39
};
Original file line number Diff line number Diff line change @@ -26,27 +26,31 @@ namespace utility
26
26
* @return A string containing the hexadecimal representation of the given buffer.
27
27
*/
28
28
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)
30
30
{
31
31
static constexpr char hex_chars[] = " 0123456789ABCDEF" ;
32
32
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
33
39
std::string hex_string;
34
- hex_string.reserve (3 * size);
40
+ hex_string.reserve (size > 0 ? ( 3 * size - 1 ) : 0 );
35
41
36
42
for (size_t i = 0 ; i < size; ++i)
37
43
{
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]);
43
45
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 ];
46
50
51
+ // Add a space delimiter after all but the last byte
47
52
if (i != (size - 1 ))
48
53
{
49
- // add a space delimiter
50
54
hex_string += ' ' ;
51
55
}
52
56
}
You can’t perform that action at this time.
0 commit comments