Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
relibc
Commits
3f4fbf90
Commit
3f4fbf90
authored
Oct 09, 2018
by
jD91mZM2
Browse files
Merge branch 'feature/optimise-memcmp' into 'master'
Optimise `memcmp` for speed See merge request
!167
parents
91675b5b
8e2b7c11
Pipeline
#1458
failed with stages
in 9 minutes and 17 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/header/string/mod.rs
View file @
3f4fbf90
...
...
@@ -73,14 +73,32 @@ pub unsafe extern "C" fn memchr(s: *const c_void, c: c_int, n: usize) -> *mut c_
#[no_mangle]
pub
unsafe
extern
"C"
fn
memcmp
(
s1
:
*
const
c_void
,
s2
:
*
const
c_void
,
n
:
usize
)
->
c_int
{
let
mut
i
=
0
;
while
i
<
n
{
let
a
=
*
(
s1
as
*
const
u8
)
.offset
(
i
as
isize
);
let
b
=
*
(
s2
as
*
const
u8
)
.offset
(
i
as
isize
);
if
a
!=
b
{
return
a
as
i32
-
b
as
i32
;
let
(
div
,
rem
)
=
(
n
/
mem
::
size_of
::
<
usize
>
(),
n
%
mem
::
size_of
::
<
usize
>
());
let
mut
a
=
s1
as
*
const
usize
;
let
mut
b
=
s2
as
*
const
usize
;
for
_
in
0
..
div
{
if
*
a
!=
*
b
{
for
i
in
0
..
mem
::
size_of
::
<
usize
>
()
{
let
c
=
*
(
a
as
*
const
u8
)
.offset
(
i
as
isize
);
let
d
=
*
(
b
as
*
const
u8
)
.offset
(
i
as
isize
);
if
c
!=
d
{
return
c
as
c_int
-
d
as
c_int
;
}
}
unreachable!
()
}
i
+=
1
;
a
=
a
.offset
(
1
);
b
=
b
.offset
(
1
);
}
let
mut
a
=
a
as
*
const
u8
;
let
mut
b
=
b
as
*
const
u8
;
for
_
in
0
..
rem
{
if
*
a
!=
*
b
{
return
a
as
c_int
-
b
as
c_int
;
}
a
=
a
.offset
(
1
);
b
=
b
.offset
(
1
);
}
0
}
...
...
Write
Preview
Supports
Markdown
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