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
3c8fad12
Commit
3c8fad12
authored
Jun 13, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize parse_nonnegative_int
parent
f28cf330
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
18 deletions
+22
-18
include/fmt/core.h
include/fmt/core.h
+22
-18
No files found.
include/fmt/core.h
View file @
3c8fad12
...
...
@@ -8,10 +8,10 @@
#ifndef FMT_CORE_H_
#define FMT_CORE_H_
#include <climits> // INT_MAX
#include <cstdio> // std::FILE
#include <cstdio> // std::FILE
#include <cstring>
#include <iterator>
#include <limits>
#include <string>
#include <type_traits>
...
...
@@ -2103,21 +2103,25 @@ template <typename Char, typename ErrorHandler>
FMT_CONSTEXPR
auto
parse_nonnegative_int
(
const
Char
*&
begin
,
const
Char
*
end
,
ErrorHandler
&&
eh
)
->
int
{
FMT_ASSERT
(
begin
!=
end
&&
'0'
<=
*
begin
&&
*
begin
<=
'9'
,
""
);
unsigned
value
=
0
;
// Convert to unsigned to prevent a warning.
const
unsigned
max_int
=
to_unsigned
(
INT_MAX
);
unsigned
big
=
max_int
/
10
;
unsigned
value
=
0
,
prev
=
0
;
auto
p
=
begin
;
do
{
// Check for overflow.
if
(
value
>
big
)
{
value
=
max_int
+
1
;
break
;
}
value
=
value
*
10
+
unsigned
(
*
begin
-
'0'
);
++
begin
;
}
while
(
begin
!=
end
&&
'0'
<=
*
begin
&&
*
begin
<=
'9'
);
if
(
value
>
max_int
)
eh
.
on_error
(
"number is too big"
);
return
static_cast
<
int
>
(
value
);
prev
=
value
;
value
=
value
*
10
+
unsigned
(
*
p
-
'0'
);
++
p
;
}
while
(
p
!=
end
&&
'0'
<=
*
p
&&
*
p
<=
'9'
);
auto
num_digits
=
p
-
begin
;
begin
=
p
;
if
(
num_digits
<=
std
::
numeric_limits
<
int
>::
digits10
)
return
static_cast
<
int
>
(
value
);
// Check for overflow.
const
unsigned
big
=
to_unsigned
((
std
::
numeric_limits
<
int
>::
max
)());
if
(
num_digits
==
std
::
numeric_limits
<
int
>::
digits10
+
1
&&
prev
*
10ull
+
unsigned
(
p
[
-
1
]
-
'0'
)
<=
big
)
{
return
static_cast
<
int
>
(
value
);
}
eh
.
on_error
(
"number is too big"
);
return
-
1
;
}
// Parses fill and alignment.
...
...
@@ -2454,8 +2458,8 @@ class compile_parse_context
public:
explicit
FMT_CONSTEXPR
compile_parse_context
(
basic_string_view
<
Char
>
format_str
,
int
num_args
=
INT_MAX
,
ErrorHandler
eh
=
{})
basic_string_view
<
Char
>
format_str
,
int
num_args
=
(
std
::
numeric_limits
<
int
>::
max
)(),
ErrorHandler
eh
=
{})
:
base
(
format_str
,
eh
),
num_args_
(
num_args
)
{}
FMT_CONSTEXPR
auto
next_arg_id
()
->
int
{
...
...
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