diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-09-13 11:46:10 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-09-13 13:24:33 -0700 |
| commit | 2f6b66ecd33c849b2d42c5188b71b61161227808 (patch) | |
| tree | 96fc7d73849bd40ecb6b303af4c3544d178c37fa /src/libcore | |
| parent | c43426e35ba89fe52cd48b70d240f5014937f71f (diff) | |
s/vec::as_buf/vec::as_imm_buf/, fix comment, remove set.rs
hat tip to @jruderman
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/comm.rs | 2 | ||||
| -rw-r--r-- | src/libcore/int-template.rs | 2 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 2 | ||||
| -rw-r--r-- | src/libcore/run.rs | 6 | ||||
| -rw-r--r-- | src/libcore/str.rs | 4 | ||||
| -rw-r--r-- | src/libcore/uint-template.rs | 4 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 37 |
7 files changed, 28 insertions, 29 deletions
diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index f9db36f0fc1..a44fae77740 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -238,7 +238,7 @@ fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>) let mut resport: *rust_port; resport = rusti::init::<*rust_port>(); - do vec::as_buf(ports) |ports, n_ports| { + do vec::as_imm_buf(ports) |ports, n_ports| { rustrt::rust_port_select(ptr::addr_of(resport), ports, n_ports as size_t, yieldp); } diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 06286906b70..a7c3c4e0d0a 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -169,7 +169,7 @@ impl T : FromStr { /// Convert to a string in a given base fn to_str(n: T, radix: uint) -> ~str { do to_str_bytes(n, radix) |slice| { - do vec::as_buf(slice) |p, len| { + do vec::as_imm_buf(slice) |p, len| { unsafe { str::raw::from_buf_len(p, len) } } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index c95e2aa6c7c..acb9953b148 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -299,7 +299,7 @@ fn test_buf_len() { do str::as_c_str(s1) |p1| { do str::as_c_str(s2) |p2| { let v = ~[p0, p1, p2, null()]; - do vec::as_buf(v) |vp, len| { + do vec::as_imm_buf(v) |vp, len| { assert unsafe { buf_len(vp) } == 3u; assert len == 4u; } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index aedc67b00f5..b99f3402ee5 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -92,7 +92,7 @@ fn with_argv<T>(prog: &str, args: &[~str], vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b])); } vec::push(argptrs, ptr::null()); - vec::as_buf(argptrs, |buf, _len| cb(buf)) + vec::as_imm_buf(argptrs, |buf, _len| cb(buf)) } #[cfg(unix)] @@ -112,7 +112,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>, vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b])); } vec::push(ptrs, ptr::null()); - vec::as_buf(ptrs, |p, _len| + vec::as_imm_buf(ptrs, |p, _len| unsafe { cb(::unsafe::reinterpret_cast(&p)) } ) } @@ -138,7 +138,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>, ::unsafe::forget(v); } blk += ~[0_u8]; - vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(&p))) + vec::as_imm_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(&p))) } _ => cb(ptr::null()) } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 7c6af7e1c40..17d6b967029 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1992,7 +1992,7 @@ mod raw { unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str { let mut v: ~[mut u8] = ~[mut]; vec::reserve(v, len + 1u); - vec::as_buf(v, |vbuf, _len| { + vec::as_imm_buf(v, |vbuf, _len| { let vbuf = ::unsafe::transmute_mut_unsafe(vbuf); ptr::memcpy(vbuf, buf as *u8, len) }); @@ -2049,7 +2049,7 @@ mod raw { let mut v = ~[]; vec::reserve(v, end - begin + 1u); unsafe { - do vec::as_buf(v) |vbuf, _vlen| { + do vec::as_imm_buf(v) |vbuf, _vlen| { let vbuf = ::unsafe::transmute_mut_unsafe(vbuf); let src = ptr::offset(sbuf, begin); ptr::memcpy(vbuf, src, end - begin); diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index 5610a00e2ca..80617fba844 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -174,7 +174,7 @@ fn from_str_radix(buf: &str, radix: u64) -> Option<u64> { */ pure fn to_str(num: T, radix: uint) -> ~str { do to_str_bytes(false, num, radix) |slice| { - do vec::as_buf(slice) |p, len| { + do vec::as_imm_buf(slice) |p, len| { unsafe { str::raw::from_buf_len(p, len) } } } @@ -219,7 +219,7 @@ pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint, // in-bounds, no extra cost. unsafe { - do vec::as_buf(buf) |p, len| { + do vec::as_imm_buf(buf) |p, len| { let mp = p as *mut u8; let mut i = len; let mut n = num; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 0f512b4ec56..bd67be910f0 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -84,7 +84,7 @@ export riter; export riteri; export permute; export windowed; -export as_buf; +export as_imm_buf; export as_mut_buf; export as_const_buf; export raw; @@ -333,7 +333,7 @@ pure fn slice<T: Copy>(v: &[const T], start: uint, end: uint) -> ~[T] { pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] { assert (start <= end); assert (end <= len(v)); - do as_buf(v) |p, _len| { + do as_imm_buf(v) |p, _len| { unsafe { ::unsafe::reinterpret_cast( &(ptr::offset(p, start), @@ -502,7 +502,7 @@ fn unshift<T>(&v: ~[T], +x: T) { } fn consume<T>(+v: ~[T], f: fn(uint, +T)) unsafe { - do as_buf(v) |p, ln| { + do as_imm_buf(v) |p, ln| { for uint::range(0, ln) |i| { let x <- *ptr::offset(p, i); f(i, move x); @@ -513,7 +513,7 @@ fn consume<T>(+v: ~[T], f: fn(uint, +T)) unsafe { } fn consume_mut<T>(+v: ~[mut T], f: fn(uint, +T)) unsafe { - do as_buf(v) |p, ln| { + do as_imm_buf(v) |p, ln| { for uint::range(0, ln) |i| { let x <- *ptr::offset(p, i); f(i, move x); @@ -605,7 +605,7 @@ fn push_all<T: Copy>(&v: ~[const T], rhs: &[const T]) { fn push_all_move<T>(&v: ~[const T], -rhs: ~[const T]) { reserve(v, v.len() + rhs.len()); unsafe { - do as_buf(rhs) |p, len| { + do as_imm_buf(rhs) |p, len| { for uint::range(0, len) |i| { let x <- *ptr::offset(p, i); push(v, move x); @@ -617,7 +617,7 @@ fn push_all_move<T>(&v: ~[const T], -rhs: ~[const T]) { /// Shorten a vector, dropping excess elements. fn truncate<T>(&v: ~[const T], newlen: uint) { - do as_buf(v) |p, oldlen| { + do as_imm_buf(v) |p, oldlen| { assert(newlen <= oldlen); unsafe { // This loop is optimized out for non-drop types. @@ -1185,7 +1185,7 @@ element's value. */ #[inline(always)] pure fn iter_between<T>(v: &[T], start: uint, end: uint, f: fn(T)) { - do as_buf(v) |base_ptr, len| { + do as_imm_buf(v) |base_ptr, len| { assert start <= end; assert end <= len; unsafe { @@ -1212,7 +1212,7 @@ pure fn each<T>(v: &[T], f: fn(T) -> bool) { // is that you are passing it to `f()` using // an immutable. - do vec::as_buf(v) |p, n| { + do vec::as_imm_buf(v) |p, n| { let mut n = n; let mut p = p; while n > 0u { @@ -1259,9 +1259,8 @@ fn each_mut_ref<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) { } } -/// Like `each()`, but for the case where you have -/// a vector with mutable contents and you would like -/// to mutate the contents as you iterate. +/// Like `each()`, but for the case where you have a vector that *may or may +/// not* have mutable contents. #[inline(always)] pure fn each_const_ref<T>(v: &[const T], f: fn(elem: &const T) -> bool) { let mut i = 0; @@ -1281,7 +1280,7 @@ pure fn each_const_ref<T>(v: &[const T], f: fn(elem: &const T) -> bool) { */ #[inline(always)] pure fn eachi<T>(v: &[T], f: fn(uint, T) -> bool) { - do vec::as_buf(v) |p, n| { + do vec::as_imm_buf(v) |p, n| { let mut i = 0u; let mut p = p; while i < n { @@ -1301,7 +1300,7 @@ pure fn eachi<T>(v: &[T], f: fn(uint, T) -> bool) { */ #[inline(always)] pure fn reach<T>(v: &[T], blk: fn(T) -> bool) { - do vec::as_buf(v) |p, n| { + do vec::as_imm_buf(v) |p, n| { let mut i = 1; while i <= n { unsafe { @@ -1319,7 +1318,7 @@ pure fn reach<T>(v: &[T], blk: fn(T) -> bool) { */ #[inline(always)] pure fn reachi<T>(v: &[T], blk: fn(uint, T) -> bool) { - do vec::as_buf(v) |p, n| { + do vec::as_imm_buf(v) |p, n| { let mut i = 1; while i <= n { unsafe { @@ -1431,10 +1430,10 @@ pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] { * foreign interop. */ #[inline(always)] -pure fn as_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */ - f: fn(*T, uint) -> U) -> U { +pure fn as_imm_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */ + f: fn(*T, uint) -> U) -> U { - // NB---People keep changing the type of s to `&[const T]`. This is + // NB---Do not change the type of s to `&[const T]`. This is // unsound. The reason is that we are going to create immutable pointers // into `s` and pass them to `f()`, but in fact they are potentially // pointing at *mutable memory*. Use `as_const_buf` or `as_mut_buf` @@ -1448,7 +1447,7 @@ pure fn as_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */ } } -/// Similar to `as_buf` but passing a `*const T` +/// Similar to `as_imm_buf` but passing a `*const T` #[inline(always)] pure fn as_const_buf<T,U>(s: &[const T], f: fn(*const T, uint) -> U) -> U { @@ -1461,7 +1460,7 @@ pure fn as_const_buf<T,U>(s: &[const T], } } -/// Similar to `as_buf` but passing a `*mut T` +/// Similar to `as_imm_buf` but passing a `*mut T` #[inline(always)] pure fn as_mut_buf<T,U>(s: &[mut T], f: fn(*mut T, uint) -> U) -> U { |
