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
f0a42346
Commit
f0a42346
authored
Oct 21, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move parsing optimization one level up
parent
86287b8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
include/fmt/format.h
include/fmt/format.h
+24
-24
No files found.
include/fmt/format.h
View file @
f0a42346
...
@@ -2340,12 +2340,11 @@ template <typename Context> class custom_formatter {
...
@@ -2340,12 +2340,11 @@ template <typename Context> class custom_formatter {
Context
&
ctx
)
Context
&
ctx
)
:
parse_ctx_
(
parse_ctx
),
ctx_
(
ctx
)
{}
:
parse_ctx_
(
parse_ctx
),
ctx_
(
ctx
)
{}
bool
operator
()(
typename
basic_format_arg
<
Context
>::
handle
h
)
const
{
void
operator
()(
typename
basic_format_arg
<
Context
>::
handle
h
)
const
{
h
.
format
(
parse_ctx_
,
ctx_
);
h
.
format
(
parse_ctx_
,
ctx_
);
return
true
;
}
}
template
<
typename
T
>
bool
operator
()(
T
)
const
{
return
false
;
}
template
<
typename
T
>
void
operator
()(
T
)
const
{
}
};
};
template
<
typename
T
>
template
<
typename
T
>
...
@@ -2739,6 +2738,10 @@ FMT_CONSTEXPR int code_point_length(const Char* begin) {
...
@@ -2739,6 +2738,10 @@ FMT_CONSTEXPR int code_point_length(const Char* begin) {
return
len
+
!
len
;
return
len
+
!
len
;
}
}
template
<
typename
Char
>
constexpr
bool
is_ascii_letter
(
Char
c
)
{
return
(
c
>=
'a'
&&
c
<=
'z'
)
||
(
c
>=
'A'
&&
c
<=
'Z'
);
}
// Converts a character to ASCII. Returns a number > 127 on conversion failure.
// Converts a character to ASCII. Returns a number > 127 on conversion failure.
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_ascii
(
Char
value
)
{
constexpr
Char
to_ascii
(
Char
value
)
{
...
@@ -2832,11 +2835,6 @@ FMT_CONSTEXPR const Char* parse_precision(const Char* begin, const Char* end,
...
@@ -2832,11 +2835,6 @@ 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
>
...
@@ -2844,11 +2842,6 @@ FMT_CONSTEXPR const Char* parse_format_specs(const Char* begin, const Char* end,
...
@@ -2844,11 +2842,6 @@ FMT_CONSTEXPR const Char* parse_format_specs(const Char* begin, const Char* end,
SpecHandler
&&
handler
)
{
SpecHandler
&&
handler
)
{
if
(
begin
==
end
)
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
;
...
@@ -3051,18 +3044,25 @@ struct format_handler : detail::error_handler {
...
@@ -3051,18 +3044,25 @@ struct format_handler : detail::error_handler {
}
}
const
Char
*
on_format_specs
(
int
id
,
const
Char
*
begin
,
const
Char
*
end
)
{
const
Char
*
on_format_specs
(
int
id
,
const
Char
*
begin
,
const
Char
*
end
)
{
advance_to
(
parse_context
,
begin
);
auto
arg
=
get_arg
(
context
,
id
);
auto
arg
=
get_arg
(
context
,
id
);
custom_formatter
<
Context
>
f
(
parse_context
,
context
);
if
(
arg
.
type
()
==
type
::
custom_type
)
{
if
(
visit_format_arg
(
f
,
arg
))
return
parse_context
.
begin
();
advance_to
(
parse_context
,
begin
);
basic_format_specs
<
Char
>
specs
;
visit_format_arg
(
custom_formatter
<
Context
>
(
parse_context
,
context
),
arg
);
using
parse_context_t
=
basic_format_parse_context
<
Char
>
;
return
parse_context
.
begin
();
specs_checker
<
specs_handler
<
parse_context_t
,
Context
>>
handler
(
}
specs_handler
<
parse_context_t
,
Context
>
(
specs
,
parse_context
,
context
),
auto
specs
=
basic_format_specs
<
Char
>
();
arg
.
type
());
if
(
begin
+
1
<
end
&&
begin
[
1
]
==
'}'
&&
is_ascii_letter
(
*
begin
))
{
begin
=
parse_format_specs
(
begin
,
end
,
handler
);
specs
.
type
=
*
begin
++
;
if
(
begin
==
end
||
*
begin
!=
'}'
)
on_error
(
"missing '}' in format string"
);
}
else
{
advance_to
(
parse_context
,
begin
);
using
parse_context_t
=
basic_format_parse_context
<
Char
>
;
specs_checker
<
specs_handler
<
parse_context_t
,
Context
>>
handler
(
specs_handler
<
parse_context_t
,
Context
>
(
specs
,
parse_context
,
context
),
arg
.
type
());
begin
=
parse_format_specs
(
begin
,
end
,
handler
);
if
(
begin
==
end
||
*
begin
!=
'}'
)
on_error
(
"missing '}' in format string"
);
}
context
.
advance_to
(
context
.
advance_to
(
visit_format_arg
(
ArgFormatter
(
context
,
&
parse_context
,
&
specs
),
arg
));
visit_format_arg
(
ArgFormatter
(
context
,
&
parse_context
,
&
specs
),
arg
));
return
begin
;
return
begin
;
...
...
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