Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
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
fmt
Commits
86287b8d
Commit
86287b8d
authored
Oct 21, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize common case in parse_format_specs
parent
8924211f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
include/fmt/format.h
include/fmt/format.h
+16
-7
test/format-test.cc
test/format-test.cc
+1
-1
No files found.
include/fmt/format.h
View file @
86287b8d
...
@@ -2739,14 +2739,13 @@ FMT_CONSTEXPR int code_point_length(const Char* begin) {
...
@@ -2739,14 +2739,13 @@ FMT_CONSTEXPR int code_point_length(const Char* begin) {
return
len
+
!
len
;
return
len
+
!
len
;
}
}
// Converts a character to
the underlying integral typ
e.
// Converts a character to
ASCII. Returns a number > 127 on conversion failur
e.
template
<
typename
Char
,
FMT_ENABLE_IF
(
std
::
is_integral
<
Char
>
::
value
)
>
template
<
typename
Char
,
FMT_ENABLE_IF
(
std
::
is_integral
<
Char
>
::
value
)
>
constexpr
Char
to_
integral
(
Char
value
)
{
constexpr
Char
to_
ascii
(
Char
value
)
{
return
value
;
return
value
;
}
}
template
<
typename
Char
,
FMT_ENABLE_IF
(
std
::
is_enum
<
Char
>
::
value
)
>
template
<
typename
Char
,
FMT_ENABLE_IF
(
std
::
is_enum
<
Char
>
::
value
)
>
constexpr
typename
std
::
underlying_type
<
Char
>::
type
to_
integral
(
Char
value
)
{
constexpr
typename
std
::
underlying_type
<
Char
>::
type
to_
ascii
(
Char
value
)
{
return
value
;
return
value
;
}
}
...
@@ -2759,7 +2758,7 @@ FMT_CONSTEXPR const Char* parse_align(const Char* begin, const Char* end,
...
@@ -2759,7 +2758,7 @@ FMT_CONSTEXPR const Char* parse_align(const Char* begin, const Char* end,
auto
p
=
begin
+
code_point_length
(
begin
);
auto
p
=
begin
+
code_point_length
(
begin
);
if
(
p
>=
end
)
p
=
begin
;
if
(
p
>=
end
)
p
=
begin
;
for
(;;)
{
for
(;;)
{
switch
(
to_
integral
(
*
p
))
{
switch
(
to_
ascii
(
*
p
))
{
case
'<'
:
case
'<'
:
align
=
align
::
left
;
align
=
align
::
left
;
break
;
break
;
...
@@ -2833,18 +2832,28 @@ FMT_CONSTEXPR const Char* parse_precision(const Char* begin, const Char* end,
...
@@ -2833,18 +2832,28 @@ FMT_CONSTEXPR const Char* parse_precision(const Char* begin, const Char* end,
return
begin
;
return
begin
;
}
}
template
<
typename
Char
>
constexpr
bool
is_ascii_letter
(
Char
c
)
{
return
(
c
>=
'a'
&&
c
<=
'z'
)
||
(
c
>=
'A'
&&
c
<=
'Z'
);
}
// Parses standard format specifiers and sends notifications about parsed
// Parses standard format specifiers and sends notifications about parsed
// components to handler.
// components to handler.
template
<
typename
Char
,
typename
SpecHandler
>
template
<
typename
Char
,
typename
SpecHandler
>
FMT_CONSTEXPR
const
Char
*
parse_format_specs
(
const
Char
*
begin
,
const
Char
*
end
,
FMT_CONSTEXPR
const
Char
*
parse_format_specs
(
const
Char
*
begin
,
const
Char
*
end
,
SpecHandler
&&
handler
)
{
SpecHandler
&&
handler
)
{
if
(
begin
==
end
||
*
begin
==
'}'
)
return
begin
;
if
(
begin
==
end
)
return
begin
;
if
(
is_ascii_letter
(
*
begin
)
&&
(
begin
+
1
==
end
||
begin
[
1
]
==
'}'
))
{
handler
.
on_type
(
*
begin
++
);
return
begin
;
}
begin
=
parse_align
(
begin
,
end
,
handler
);
begin
=
parse_align
(
begin
,
end
,
handler
);
if
(
begin
==
end
)
return
begin
;
if
(
begin
==
end
)
return
begin
;
// Parse sign.
// Parse sign.
switch
(
to_
integral
(
*
begin
))
{
switch
(
to_
ascii
(
*
begin
))
{
case
'+'
:
case
'+'
:
handler
.
on_plus
();
handler
.
on_plus
();
++
begin
;
++
begin
;
...
...
test/format-test.cc
View file @
86287b8d
...
@@ -2423,7 +2423,7 @@ struct custom_char {
...
@@ -2423,7 +2423,7 @@ struct custom_char {
operator
int
()
const
{
return
value
;
}
operator
int
()
const
{
return
value
;
}
};
};
int
to_
integral
(
custom_char
c
)
{
return
c
;
}
int
to_
ascii
(
custom_char
c
)
{
return
c
;
}
FMT_BEGIN_NAMESPACE
FMT_BEGIN_NAMESPACE
template
<
>
struct
is_char
<
custom_char
>
:
std
::
true_type
{};
template
<
>
struct
is_char
<
custom_char
>
:
std
::
true_type
{};
...
...
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