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
3cdf2b7f
Commit
3cdf2b7f
authored
Nov 11, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
micro optimize scoped_padder
parent
3ff541cf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
24 deletions
+12
-24
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+12
-24
No files found.
include/spdlog/details/pattern_formatter.h
View file @
3cdf2b7f
...
@@ -48,31 +48,29 @@ struct padding_info
...
@@ -48,31 +48,29 @@ struct padding_info
class
scoped_pad
class
scoped_pad
{
{
public:
public:
static
const
size_t
max_width
=
128
;
scoped_pad
(
size_t
wrapped_size
,
padding_info
&
padinfo
,
fmt
::
memory_buffer
&
dest
)
:
scoped_pad
(
size_t
wrapped_size
,
padding_info
&
padinfo
,
fmt
::
memory_buffer
&
dest
)
:
padinfo_
(
padinfo
)
padinfo_
(
padinfo
)
,
dest_
(
dest
)
,
dest_
(
dest
)
,
nchars_
(
padinfo_
.
width_
>
wrapped_size
?
padinfo_
.
width_
-
wrapped_size
:
0
)
{
{
if
(
nchars_
==
0
)
if
(
padinfo_
.
width_
<=
wrapped_size
)
{
{
nchars_
=
0
;
return
;
return
;
}
}
nchars_
=
padinfo
.
width_
-
wrapped_size
;
if
(
padinfo_
.
side_
==
padding_info
::
left
)
if
(
padinfo_
.
side_
==
padding_info
::
left
)
{
{
pad_it
(
nchars_
);
pad_it
(
nchars_
);
nchars_
=
0
;
nchars_
=
0
;
return
;
}
}
else
if
(
padinfo_
.
side_
==
padding_info
::
center
)
else
if
(
padinfo_
.
side_
==
padding_info
::
center
)
{
{
auto
half_chars
=
nchars_
/
2
;
pad_it
(
nchars_
/
2
);
auto
reminder
=
nchars_
%
2
;
return
;
pad_it
(
half_chars
);
nchars_
=
half_chars
+
reminder
;
//for the right side
}
}
}
}
...
@@ -83,27 +81,17 @@ public:
...
@@ -83,27 +81,17 @@ public:
~
scoped_pad
()
~
scoped_pad
()
{
{
if
(
nchars_
)
if
(
nchars_
==
0
)
{
return
;
}
if
(
padinfo_
.
side_
==
padding_info
::
right
)
{
{
pad_it
(
nchars_
);
pad_it
(
nchars_
);
}
}
else
// padinfo_.side_ == padding_info::center
{
pad_it
(
(
nchars_
/
2
)
+
(
nchars_
%
2
)
)
;
}
}
}
private:
private:
void
pad_it
(
size_t
count
)
void
pad_it
(
size_t
count
)
{
{
//count = std::min(count, spaces_.size());
//count = std::min(count, spaces_.size());
assert
(
count
<=
spaces_
.
size
());
fmt_helper
::
append_string_view
(
string_view_t
(
spaces_
.
data
(),
count
),
dest_
);
fmt_helper
::
append_string_view
(
string_view_t
(
spaces_
.
data
(),
count
),
dest_
);
}
}
...
@@ -1083,7 +1071,7 @@ private:
...
@@ -1083,7 +1071,7 @@ private:
{
{
using
details
::
padding_info
;
using
details
::
padding_info
;
using
details
::
scoped_pad
;
using
details
::
scoped_pad
;
const
size_t
max_width
=
128
;
if
(
it
==
end
)
if
(
it
==
end
)
{
{
return
padding_info
();
return
padding_info
();
...
@@ -1116,7 +1104,7 @@ private:
...
@@ -1116,7 +1104,7 @@ private:
auto
digit
=
static_cast
<
size_t
>
(
*
it
-
'0'
);
auto
digit
=
static_cast
<
size_t
>
(
*
it
-
'0'
);
width
=
width
*
10
+
digit
;
width
=
width
*
10
+
digit
;
}
}
return
details
::
padding_info
{
std
::
min
(
width
,
scoped_pad
::
max_width
),
side
};
return
details
::
padding_info
{
std
::
min
(
width
,
max_width
),
side
};
}
}
void
compile_pattern_
(
const
std
::
string
&
pattern
)
void
compile_pattern_
(
const
std
::
string
&
pattern
)
...
...
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