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
2989e998
Commit
2989e998
authored
Jun 13, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed up pattern_formatter
parent
3f438a80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
14 deletions
+64
-14
include/spdlog/details/pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+64
-14
No files found.
include/spdlog/details/pattern_formatter_impl.h
View file @
2989e998
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#include <utility>
#include <utility>
#include <vector>
#include <vector>
namespace
{
namespace
{
// Some fmt helpers to efficiently format and pad ints and strings
inline
void
append_str
(
const
std
::
string
&
str
,
fmt
::
memory_buffer
&
dest
)
inline
void
append_str
(
const
std
::
string
&
str
,
fmt
::
memory_buffer
&
dest
)
{
{
const
char
*
str_ptr
=
str
.
data
();
const
char
*
str_ptr
=
str
.
data
();
...
@@ -47,35 +47,87 @@ inline void append_size_t(size_t n, fmt::memory_buffer &dest)
...
@@ -47,35 +47,87 @@ inline void append_size_t(size_t n, fmt::memory_buffer &dest)
inline
void
append_and_pad2
(
int
n
,
fmt
::
memory_buffer
&
dest
)
inline
void
append_and_pad2
(
int
n
,
fmt
::
memory_buffer
&
dest
)
{
{
if
(
n
>
9
)
if
(
n
<
0
)
// should not happen in this formatter, but just in case, let fmt deal with negatives correctly
{
{
fmt
::
format_to
(
dest
,
"{:02}"
,
n
);
append_int
(
n
,
dest
);
return
;
return
;
}
}
if
(
n
<
10
)
if
(
n
>=
0
)
// 0-9
{
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
append_int
(
n
,
dest
);
return
;
}
}
append_int
(
n
,
dest
);
// negatives (unlikely but just in case, let fmt deal with it)
fmt
::
format_to
(
dest
,
"{:02}"
,
n
);
}
}
inline
void
append_and_pad3
(
int
n
,
fmt
::
memory_buffer
&
dest
)
inline
void
append_and_pad3
(
int
n
,
fmt
::
memory_buffer
&
dest
)
{
{
if
(
n
>
99
)
{
append_int
(
n
,
dest
);
return
;
}
if
(
n
>
9
)
// 10-99
{
dest
.
push_back
(
'0'
);
append_int
(
n
,
dest
);
return
;
}
if
(
n
>=
0
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
append_int
(
n
,
dest
);
return
;
}
// negatives (unlikely, but just in case let fmt deal with it)
fmt
::
format_to
(
dest
,
"{:03}"
,
n
);
}
if
(
n
<
0
)
// should not happen in this formatter, but just in case, let fmt deal with negatives correctly
void
append_and_pad6
(
int
n
,
fmt
::
memory_buffer
&
dest
)
{
if
(
n
>
99999
)
{
{
fmt
::
format_to
(
dest
,
"{:03}"
,
n
);
append_int
(
n
,
dest
);
return
;
return
;
}
}
if
(
n
<
10
)
if
(
n
>
9999
)
{
dest
.
push_back
(
'0'
);
}
else
if
(
n
>
999
)
{
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
}
else
if
(
n
<
100
)
else
if
(
n
>
99
)
{
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
else
if
(
n
>
9
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
else
if
(
n
>=
0
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
else
// negatives (unlikely, but just in case let fmt deal with it)
{
fmt
::
format_to
(
dest
,
"{:06}"
,
n
);
return
;
}
}
append_int
(
n
,
dest
);
append_int
(
n
,
dest
);
}
}
...
@@ -309,7 +361,7 @@ class f_formatter SPDLOG_FINAL : public flag_formatter
...
@@ -309,7 +361,7 @@ class f_formatter SPDLOG_FINAL : public flag_formatter
{
{
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
micros
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
duration
).
count
()
%
1000000
;
auto
micros
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
duration
).
count
()
%
1000000
;
fmt
::
format_to
(
msg
.
formatted
,
"{:06}"
,
static_cast
<
int
>
(
micros
)
);
append_and_pad6
(
static_cast
<
int
>
(
micros
),
msg
.
formatted
);
}
}
};
};
...
@@ -544,9 +596,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
...
@@ -544,9 +596,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
// tm_time.tm_mday, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec, static_cast<int>(millis));
// tm_time.tm_mday, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec, static_cast<int>(millis));
msg
.
formatted
.
push_back
(
'['
);
msg
.
formatted
.
push_back
(
'['
);
append_int
(
tm_time
.
tm_year
+
1900
,
msg
.
formatted
);
fmt
::
format_int
i
(
tm_time
.
tm_year
+
1900
);
msg
.
formatted
.
append
(
i
.
data
(),
i
.
data
()
+
i
.
size
());
msg
.
formatted
.
push_back
(
'-'
);
msg
.
formatted
.
push_back
(
'-'
);
append_and_pad2
(
tm_time
.
tm_mon
+
1
,
msg
.
formatted
);
append_and_pad2
(
tm_time
.
tm_mon
+
1
,
msg
.
formatted
);
...
...
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