提交 971b5910 编写于 作者: E Erick Tryzelaar 提交者: Graydon Hoare

libcore: add vec memcpy and memmove fns

上级 9d4aab80
......@@ -1598,6 +1598,34 @@ unsafe fn form_slice<T,U>(p: *T, len: uint, f: fn(&& &[T]) -> U) -> U {
::unsafe::reinterpret_cast(ptr::addr_of(pair));
f(*v)
}
/**
* Copies data from one vector to another.
*
* Copies `count` bytes from `src` to `dst`. The source and destination
* may overlap.
*/
unsafe fn memcpy<T>(dst: &[mut T], src: &[const T], count: uint) {
do unpack_slice(dst) |p_dst, _len_dst| {
do unpack_slice(src) |p_src, _len_src| {
ptr::memcpy(p_dst, p_src, count)
}
}
}
/**
* Copies data from one vector to another.
*
* Copies `count` bytes from `src` to `dst`. The source and destination
* may overlap.
*/
unsafe fn memmove<T>(dst: &[mut T], src: &[const T], count: uint) {
do unpack_slice(dst) |p_dst, _len_dst| {
do unpack_slice(src) |p_src, _len_src| {
ptr::memmove(p_dst, p_src, count)
}
}
}
}
/// Operations on `[u8]`
......@@ -1605,6 +1633,7 @@ mod u8 {
export cmp;
export lt, le, eq, ne, ge, gt;
export hash;
export memcpy, memmove;
/// Bytewise string comparison
pure fn cmp(&&a: ~[u8], &&b: ~[u8]) -> int {
......@@ -1655,6 +1684,32 @@ fn hash(&&s: ~[u8]) -> uint {
vec::iter(s, |c| {u *= 33u; u += c as uint;});
ret u;
}
/**
* Copies data from one vector to another.
*
* Copies `count` bytes from `src` to `dst`. The source and destination
* may not overlap.
*/
fn memcpy(dst: &[mut u8], src: &[const u8], count: uint) {
assert dst.len() >= count;
assert src.len() >= count;
unsafe { vec::unsafe::memcpy(dst, src, count) }
}
/**
* Copies data from one vector to another.
*
* Copies `count` bytes from `src` to `dst`. The source and destination
* may overlap.
*/
fn memmove(dst: &[mut u8], src: &[const u8], count: uint) {
assert dst.len() >= count;
assert src.len() >= count;
unsafe { vec::unsafe::memmove(dst, src, count) }
}
}
// ___________________________________________________________________________
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册