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
30a56ba6
Commit
30a56ba6
authored
Mar 14, 2019
by
romkatv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize string comparisons
parent
5f188c48
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
19 deletions
+15
-19
src/util.c
+12
-17
src/util.h
+3
-2
No files found.
src/util.c
View file @
30a56ba6
...
...
@@ -204,13 +204,6 @@ int git__strntol32(int32_t *result, const char *nptr, size_t nptr_len, const cha
return
error
;
}
int
git__strcmp
(
const
char
*
a
,
const
char
*
b
)
{
while
(
*
a
&&
*
b
&&
*
a
==
*
b
)
++
a
,
++
b
;
return
(
int
)(
*
(
const
unsigned
char
*
)
a
)
-
(
int
)(
*
(
const
unsigned
char
*
)
b
);
}
int
git__strcasecmp
(
const
char
*
a
,
const
char
*
b
)
{
while
(
*
a
&&
*
b
&&
git__tolower
(
*
a
)
==
git__tolower
(
*
b
))
...
...
@@ -240,15 +233,6 @@ int git__strcasesort_cmp(const char *a, const char *b)
return
cmp
;
}
int
git__strncmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
)
{
while
(
sz
&&
*
a
&&
*
b
&&
*
a
==
*
b
)
--
sz
,
++
a
,
++
b
;
if
(
!
sz
)
return
0
;
return
(
int
)(
*
(
const
unsigned
char
*
)
a
)
-
(
int
)(
*
(
const
unsigned
char
*
)
b
);
}
int
git__strncasecmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
)
{
int
al
,
bl
;
...
...
@@ -301,7 +285,18 @@ GIT_INLINE(int) prefixcmp(const char *str, size_t str_n, const char *prefix, boo
int
git__prefixcmp
(
const
char
*
str
,
const
char
*
prefix
)
{
return
prefixcmp
(
str
,
SIZE_MAX
,
prefix
,
false
);
unsigned
char
s
,
p
;
while
(
1
)
{
p
=
*
prefix
++
;
s
=
*
str
++
;
if
(
!
p
)
return
0
;
if
(
s
!=
p
)
return
s
-
p
;
}
}
int
git__prefixncmp
(
const
char
*
str
,
size_t
str_n
,
const
char
*
prefix
)
...
...
src/util.h
View file @
30a56ba6
...
...
@@ -150,12 +150,13 @@ extern int git__bsearch_r(
void
*
payload
,
size_t
*
position
);
#define git__strcmp strcmp
#define git__strncmp strncmp
extern
int
git__strcmp_cb
(
const
void
*
a
,
const
void
*
b
);
extern
int
git__strcasecmp_cb
(
const
void
*
a
,
const
void
*
b
);
extern
int
git__strcmp
(
const
char
*
a
,
const
char
*
b
);
extern
int
git__strcasecmp
(
const
char
*
a
,
const
char
*
b
);
extern
int
git__strncmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
);
extern
int
git__strncasecmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
);
extern
int
git__strcasesort_cmp
(
const
char
*
a
,
const
char
*
b
);
...
...
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