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
397ad1be
Commit
397ad1be
authored
Jun 15, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize common case
parent
7431165f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
3 deletions
+21
-3
include/fmt/format-inl.h
include/fmt/format-inl.h
+19
-0
include/fmt/format.h
include/fmt/format.h
+1
-2
test/format-test.cc
test/format-test.cc
+1
-1
No files found.
include/fmt/format-inl.h
View file @
397ad1be
...
...
@@ -1365,7 +1365,26 @@ FMT_FUNC void report_system_error(int error_code,
report_error
(
format_system_error
,
error_code
,
message
);
}
struct
stringifier
{
template
<
typename
T
>
FMT_INLINE
std
::
string
operator
()(
T
value
)
const
{
return
to_string
(
value
);
}
std
::
string
operator
()(
basic_format_arg
<
format_context
>::
handle
h
)
const
{
memory_buffer
buf
;
internal
::
buffer
<
char
>&
base
=
buf
;
format_parse_context
parse_ctx
({});
format_context
format_ctx
(
std
::
back_inserter
(
base
),
{},
{});
h
.
format
(
parse_ctx
,
format_ctx
);
return
to_string
(
buf
);
}
};
FMT_FUNC
std
::
string
detail
::
vformat
(
string_view
format_str
,
format_args
args
)
{
if
(
format_str
.
size
()
==
2
&&
equal2
(
format_str
.
data
(),
"{}"
))
{
auto
arg
=
args
.
get
(
0
);
if
(
!
arg
)
error_handler
().
on_error
(
"argument not found"
);
return
visit_format_arg
(
stringifier
(),
arg
);
}
memory_buffer
buffer
;
detail
::
vformat_to
(
buffer
,
format_str
,
args
);
return
to_string
(
buffer
);
...
...
include/fmt/format.h
View file @
397ad1be
...
...
@@ -1766,8 +1766,7 @@ template <typename OutputIt, typename Char> struct default_arg_formatter {
}
OutputIt
operator
()(
typename
basic_format_arg
<
context
>::
handle
handle
)
{
auto
s
=
Char
(
'}'
);
basic_format_parse_context
<
Char
>
parse_ctx
(
basic_string_view
<
Char
>
(
&
s
,
1
));
basic_format_parse_context
<
Char
>
parse_ctx
({});
basic_format_context
<
OutputIt
,
Char
>
format_ctx
(
out
,
args
,
loc
);
handle
.
format
(
parse_ctx
,
format_ctx
);
return
format_ctx
.
out
();
...
...
test/format-test.cc
View file @
397ad1be
...
...
@@ -1475,7 +1475,7 @@ template <> struct formatter<Date> {
template
<
typename
ParseContext
>
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
auto
it
=
ctx
.
begin
();
if
(
*
it
==
'd'
)
++
it
;
if
(
it
!=
ctx
.
end
()
&&
*
it
==
'd'
)
++
it
;
return
it
;
}
...
...
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