Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
d38bd138
Commit
d38bd138
authored
Apr 12, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Micro optimze pattern-formatter when padding not needed
parent
7766bc25
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
1 deletion
+58
-1
include/spdlog/pattern_formatter-inl.h
include/spdlog/pattern_formatter-inl.h
+58
-1
No files found.
include/spdlog/pattern_formatter-inl.h
View file @
d38bd138
...
...
@@ -644,6 +644,22 @@ public:
}
};
// If padding is not needed, there is no need to count the digits of the thread id
template
<
>
class
t_formatter
<
null_scoped_padder
>
final
:
public
flag_formatter
{
public:
explicit
t_formatter
(
padding_info
padinfo
)
:
flag_formatter
(
padinfo
)
{}
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
memory_buf_t
&
dest
)
override
{
fmt_helper
::
append_int
(
msg
.
thread_id
,
dest
);
}
};
// Current pid
template
<
typename
ScopedPadder
>
class
pid_formatter
final
:
public
flag_formatter
...
...
@@ -662,6 +678,23 @@ public:
}
};
// If padding is not needed, there is no need to count the digits of the pid
template
<
>
class
pid_formatter
<
null_scoped_padder
>
final
:
public
flag_formatter
{
public:
explicit
pid_formatter
(
padding_info
padinfo
)
:
flag_formatter
(
padinfo
)
{}
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
,
memory_buf_t
&
dest
)
override
{
const
auto
pid
=
static_cast
<
uint32_t
>
(
details
::
os
::
pid
());
fmt_helper
::
append_int
(
pid
,
dest
);
}
};
template
<
typename
ScopedPadder
>
class
v_formatter
final
:
public
flag_formatter
{
...
...
@@ -857,7 +890,6 @@ public:
// print elapsed time since last message
template
<
typename
ScopedPadder
,
typename
Units
>
class
elapsed_formatter
final
:
public
flag_formatter
{
public:
...
...
@@ -883,6 +915,31 @@ private:
log_clock
::
time_point
last_message_time_
;
};
// If padding is not needed, there is no need to count the digits of the value
template
<
typename
Units
>
class
elapsed_formatter
<
null_scoped_padder
,
Units
>
final
:
public
flag_formatter
{
public:
using
DurationUnits
=
Units
;
explicit
elapsed_formatter
(
padding_info
padinfo
)
:
flag_formatter
(
padinfo
)
,
last_message_time_
(
log_clock
::
now
())
{}
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
memory_buf_t
&
dest
)
override
{
auto
delta
=
(
std
::
max
)(
msg
.
time
-
last_message_time_
,
log_clock
::
duration
::
zero
());
auto
delta_units
=
std
::
chrono
::
duration_cast
<
DurationUnits
>
(
delta
);
last_message_time_
=
msg
.
time
;
auto
delta_count
=
static_cast
<
size_t
>
(
delta_units
.
count
());
fmt_helper
::
append_int
(
delta_count
,
dest
);
}
private:
log_clock
::
time_point
last_message_time_
;
};
// Full info formatter
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
class
full_formatter
final
:
public
flag_formatter
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment