Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
851e778e
Unverified
Commit
851e778e
authored
Dec 13, 2020
by
Edward Thomson
Committed by
GitHub
Dec 13, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5735 from lhchavez/faster-strntol64
Make git__strntol64() ~70%* faster
parents
86a1cdd3
e99e833f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
11 deletions
+34
-11
src/integer.h
+31
-0
src/util.c
+3
-11
No files found.
src/integer.h
View file @
851e778e
...
...
@@ -77,6 +77,11 @@ GIT_INLINE(int) git__is_int(long long p)
# define git__sub_int_overflow(out, one, two) \
__builtin_ssub_overflow(one, two, out)
# define git__add_int64_overflow(out, one, two) \
__builtin_add_overflow(one, two, out)
# define git__multiply_int64_overflow(out, one, two) \
__builtin_mul_overflow(one, two, out)
/* Use Microsoft's safe integer handling functions where available */
#elif defined(_MSC_VER)
...
...
@@ -87,11 +92,17 @@ GIT_INLINE(int) git__is_int(long long p)
(SizeTAdd(one, two, out) != S_OK)
# define git__multiply_sizet_overflow(out, one, two) \
(SizeTMult(one, two, out) != S_OK)
#define git__add_int_overflow(out, one, two) \
(IntAdd(one, two, out) != S_OK)
#define git__sub_int_overflow(out, one, two) \
(IntSub(one, two, out) != S_OK)
#define git__add_int64_overflow(out, one, two) \
(LongLongAdd(one, two, out) != S_OK)
#define git__multiply_int64_overflow(out, one, two) \
(LongLongMult(one, two, out) != S_OK)
#else
/**
...
...
@@ -136,6 +147,26 @@ GIT_INLINE(bool) git__sub_int_overflow(int *out, int one, int two)
return
false
;
}
GIT_INLINE
(
bool
)
git__add_int64_overflow
(
int64_t
*
out
,
int64_t
one
,
int64_t
two
)
{
if
((
two
>
0
&&
one
>
(
INT64_MAX
-
two
))
||
(
two
<
0
&&
one
<
(
INT64_MIN
-
two
)))
return
true
;
*
out
=
one
+
two
;
return
false
;
}
GIT_INLINE
(
bool
)
git__multiply_int64_overflow
(
int64_t
*
out
,
int64_t
one
,
int64_t
two
)
{
if
((
one
==
-
1
&&
two
==
INT_MIN
)
||
(
two
==
-
1
&&
one
==
INT_MIN
)
||
(
one
&&
INT64_MAX
/
one
<
two
)
||
(
one
&&
INT64_MIN
/
one
>
two
))
return
true
;
*
out
=
one
*
two
;
return
false
;
}
#endif
#endif
src/util.c
View file @
851e778e
...
...
@@ -34,8 +34,8 @@
int
git__strntol64
(
int64_t
*
result
,
const
char
*
nptr
,
size_t
nptr_len
,
const
char
**
endptr
,
int
base
)
{
const
char
*
p
;
int64_t
n
,
nn
;
int
c
,
ovfl
,
v
,
neg
,
ndig
;
int64_t
n
,
nn
,
v
;
int
c
,
ovfl
,
neg
,
ndig
;
p
=
nptr
;
neg
=
0
;
...
...
@@ -110,19 +110,11 @@ int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const cha
if
(
v
>=
base
)
break
;
v
=
neg
?
-
v
:
v
;
if
(
n
>
INT64_MAX
/
base
||
n
<
INT64_MIN
/
base
)
{
if
(
git__multiply_int64_overflow
(
&
nn
,
n
,
base
)
||
git__add_int64_overflow
(
&
n
,
nn
,
v
)
)
{
ovfl
=
1
;
/* Keep on iterating until the end of this number */
continue
;
}
nn
=
n
*
base
;
if
((
v
>
0
&&
nn
>
INT64_MAX
-
v
)
||
(
v
<
0
&&
nn
<
INT64_MIN
-
v
))
{
ovfl
=
1
;
/* Keep on iterating until the end of this number */
continue
;
}
n
=
nn
+
v
;
}
Return:
...
...
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