Skip to content

Commit 2f6b66e

Browse files
committed
s/vec::as_buf/vec::as_imm_buf/, fix comment, remove set.rs
hat tip to @jruderman
1 parent c43426e commit 2f6b66e

File tree

14 files changed

+36
-99
lines changed

14 files changed

+36
-99
lines changed

src/libcore/comm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
238238

239239
let mut resport: *rust_port;
240240
resport = rusti::init::<*rust_port>();
241-
do vec::as_buf(ports) |ports, n_ports| {
241+
do vec::as_imm_buf(ports) |ports, n_ports| {
242242
rustrt::rust_port_select(ptr::addr_of(resport), ports,
243243
n_ports as size_t, yieldp);
244244
}

src/libcore/int-template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl T : FromStr {
169169
/// Convert to a string in a given base
170170
fn to_str(n: T, radix: uint) -> ~str {
171171
do to_str_bytes(n, radix) |slice| {
172-
do vec::as_buf(slice) |p, len| {
172+
do vec::as_imm_buf(slice) |p, len| {
173173
unsafe { str::raw::from_buf_len(p, len) }
174174
}
175175
}

src/libcore/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn test_buf_len() {
299299
do str::as_c_str(s1) |p1| {
300300
do str::as_c_str(s2) |p2| {
301301
let v = ~[p0, p1, p2, null()];
302-
do vec::as_buf(v) |vp, len| {
302+
do vec::as_imm_buf(v) |vp, len| {
303303
assert unsafe { buf_len(vp) } == 3u;
304304
assert len == 4u;
305305
}

src/libcore/run.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn with_argv<T>(prog: &str, args: &[~str],
9292
vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b]));
9393
}
9494
vec::push(argptrs, ptr::null());
95-
vec::as_buf(argptrs, |buf, _len| cb(buf))
95+
vec::as_imm_buf(argptrs, |buf, _len| cb(buf))
9696
}
9797

9898
#[cfg(unix)]
@@ -112,7 +112,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
112112
vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b]));
113113
}
114114
vec::push(ptrs, ptr::null());
115-
vec::as_buf(ptrs, |p, _len|
115+
vec::as_imm_buf(ptrs, |p, _len|
116116
unsafe { cb(::unsafe::reinterpret_cast(&p)) }
117117
)
118118
}
@@ -138,7 +138,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
138138
::unsafe::forget(v);
139139
}
140140
blk += ~[0_u8];
141-
vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(&p)))
141+
vec::as_imm_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(&p)))
142142
}
143143
_ => cb(ptr::null())
144144
}

src/libcore/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ mod raw {
19921992
unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str {
19931993
let mut v: ~[mut u8] = ~[mut];
19941994
vec::reserve(v, len + 1u);
1995-
vec::as_buf(v, |vbuf, _len| {
1995+
vec::as_imm_buf(v, |vbuf, _len| {
19961996
let vbuf = ::unsafe::transmute_mut_unsafe(vbuf);
19971997
ptr::memcpy(vbuf, buf as *u8, len)
19981998
});
@@ -2049,7 +2049,7 @@ mod raw {
20492049
let mut v = ~[];
20502050
vec::reserve(v, end - begin + 1u);
20512051
unsafe {
2052-
do vec::as_buf(v) |vbuf, _vlen| {
2052+
do vec::as_imm_buf(v) |vbuf, _vlen| {
20532053
let vbuf = ::unsafe::transmute_mut_unsafe(vbuf);
20542054
let src = ptr::offset(sbuf, begin);
20552055
ptr::memcpy(vbuf, src, end - begin);

src/libcore/uint-template.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn from_str_radix(buf: &str, radix: u64) -> Option<u64> {
174174
*/
175175
pure fn to_str(num: T, radix: uint) -> ~str {
176176
do to_str_bytes(false, num, radix) |slice| {
177-
do vec::as_buf(slice) |p, len| {
177+
do vec::as_imm_buf(slice) |p, len| {
178178
unsafe { str::raw::from_buf_len(p, len) }
179179
}
180180
}
@@ -219,7 +219,7 @@ pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
219219
// in-bounds, no extra cost.
220220

221221
unsafe {
222-
do vec::as_buf(buf) |p, len| {
222+
do vec::as_imm_buf(buf) |p, len| {
223223
let mp = p as *mut u8;
224224
let mut i = len;
225225
let mut n = num;

src/libcore/vec.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export riter;
8484
export riteri;
8585
export permute;
8686
export windowed;
87-
export as_buf;
87+
export as_imm_buf;
8888
export as_mut_buf;
8989
export as_const_buf;
9090
export raw;
@@ -333,7 +333,7 @@ pure fn slice<T: Copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
333333
pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
334334
assert (start <= end);
335335
assert (end <= len(v));
336-
do as_buf(v) |p, _len| {
336+
do as_imm_buf(v) |p, _len| {
337337
unsafe {
338338
::unsafe::reinterpret_cast(
339339
&(ptr::offset(p, start),
@@ -502,7 +502,7 @@ fn unshift<T>(&v: ~[T], +x: T) {
502502
}
503503

504504
fn consume<T>(+v: ~[T], f: fn(uint, +T)) unsafe {
505-
do as_buf(v) |p, ln| {
505+
do as_imm_buf(v) |p, ln| {
506506
for uint::range(0, ln) |i| {
507507
let x <- *ptr::offset(p, i);
508508
f(i, move x);
@@ -513,7 +513,7 @@ fn consume<T>(+v: ~[T], f: fn(uint, +T)) unsafe {
513513
}
514514

515515
fn consume_mut<T>(+v: ~[mut T], f: fn(uint, +T)) unsafe {
516-
do as_buf(v) |p, ln| {
516+
do as_imm_buf(v) |p, ln| {
517517
for uint::range(0, ln) |i| {
518518
let x <- *ptr::offset(p, i);
519519
f(i, move x);
@@ -605,7 +605,7 @@ fn push_all<T: Copy>(&v: ~[const T], rhs: &[const T]) {
605605
fn push_all_move<T>(&v: ~[const T], -rhs: ~[const T]) {
606606
reserve(v, v.len() + rhs.len());
607607
unsafe {
608-
do as_buf(rhs) |p, len| {
608+
do as_imm_buf(rhs) |p, len| {
609609
for uint::range(0, len) |i| {
610610
let x <- *ptr::offset(p, i);
611611
push(v, move x);
@@ -617,7 +617,7 @@ fn push_all_move<T>(&v: ~[const T], -rhs: ~[const T]) {
617617

618618
/// Shorten a vector, dropping excess elements.
619619
fn truncate<T>(&v: ~[const T], newlen: uint) {
620-
do as_buf(v) |p, oldlen| {
620+
do as_imm_buf(v) |p, oldlen| {
621621
assert(newlen <= oldlen);
622622
unsafe {
623623
// This loop is optimized out for non-drop types.
@@ -1185,7 +1185,7 @@ element's value.
11851185
*/
11861186
#[inline(always)]
11871187
pure fn iter_between<T>(v: &[T], start: uint, end: uint, f: fn(T)) {
1188-
do as_buf(v) |base_ptr, len| {
1188+
do as_imm_buf(v) |base_ptr, len| {
11891189
assert start <= end;
11901190
assert end <= len;
11911191
unsafe {
@@ -1212,7 +1212,7 @@ pure fn each<T>(v: &[T], f: fn(T) -> bool) {
12121212
// is that you are passing it to `f()` using
12131213
// an immutable.
12141214

1215-
do vec::as_buf(v) |p, n| {
1215+
do vec::as_imm_buf(v) |p, n| {
12161216
let mut n = n;
12171217
let mut p = p;
12181218
while n > 0u {
@@ -1259,9 +1259,8 @@ fn each_mut_ref<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) {
12591259
}
12601260
}
12611261

1262-
/// Like `each()`, but for the case where you have
1263-
/// a vector with mutable contents and you would like
1264-
/// to mutate the contents as you iterate.
1262+
/// Like `each()`, but for the case where you have a vector that *may or may
1263+
/// not* have mutable contents.
12651264
#[inline(always)]
12661265
pure fn each_const_ref<T>(v: &[const T], f: fn(elem: &const T) -> bool) {
12671266
let mut i = 0;
@@ -1281,7 +1280,7 @@ pure fn each_const_ref<T>(v: &[const T], f: fn(elem: &const T) -> bool) {
12811280
*/
12821281
#[inline(always)]
12831282
pure fn eachi<T>(v: &[T], f: fn(uint, T) -> bool) {
1284-
do vec::as_buf(v) |p, n| {
1283+
do vec::as_imm_buf(v) |p, n| {
12851284
let mut i = 0u;
12861285
let mut p = p;
12871286
while i < n {
@@ -1301,7 +1300,7 @@ pure fn eachi<T>(v: &[T], f: fn(uint, T) -> bool) {
13011300
*/
13021301
#[inline(always)]
13031302
pure fn reach<T>(v: &[T], blk: fn(T) -> bool) {
1304-
do vec::as_buf(v) |p, n| {
1303+
do vec::as_imm_buf(v) |p, n| {
13051304
let mut i = 1;
13061305
while i <= n {
13071306
unsafe {
@@ -1319,7 +1318,7 @@ pure fn reach<T>(v: &[T], blk: fn(T) -> bool) {
13191318
*/
13201319
#[inline(always)]
13211320
pure fn reachi<T>(v: &[T], blk: fn(uint, T) -> bool) {
1322-
do vec::as_buf(v) |p, n| {
1321+
do vec::as_imm_buf(v) |p, n| {
13231322
let mut i = 1;
13241323
while i <= n {
13251324
unsafe {
@@ -1431,10 +1430,10 @@ pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
14311430
* foreign interop.
14321431
*/
14331432
#[inline(always)]
1434-
pure fn as_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */
1435-
f: fn(*T, uint) -> U) -> U {
1433+
pure fn as_imm_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */
1434+
f: fn(*T, uint) -> U) -> U {
14361435

1437-
// NB---People keep changing the type of s to `&[const T]`. This is
1436+
// NB---Do not change the type of s to `&[const T]`. This is
14381437
// unsound. The reason is that we are going to create immutable pointers
14391438
// into `s` and pass them to `f()`, but in fact they are potentially
14401439
// 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 */
14481447
}
14491448
}
14501449

1451-
/// Similar to `as_buf` but passing a `*const T`
1450+
/// Similar to `as_imm_buf` but passing a `*const T`
14521451
#[inline(always)]
14531452
pure fn as_const_buf<T,U>(s: &[const T],
14541453
f: fn(*const T, uint) -> U) -> U {
@@ -1461,7 +1460,7 @@ pure fn as_const_buf<T,U>(s: &[const T],
14611460
}
14621461
}
14631462

1464-
/// Similar to `as_buf` but passing a `*mut T`
1463+
/// Similar to `as_imm_buf` but passing a `*mut T`
14651464
#[inline(always)]
14661465
pure fn as_mut_buf<T,U>(s: &[mut T],
14671466
f: fn(*mut T, uint) -> U) -> U {

src/libstd/par.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn map_slices<A: Copy Send, B: Copy Send>(
3939
log(info, ~"spawning tasks");
4040
while base < len {
4141
let end = uint::min(len, base + items_per_task);
42-
do vec::as_buf(xs) |p, _len| {
42+
do vec::as_imm_buf(xs) |p, _len| {
4343
let f = f();
4444
let f = do future_spawn() |move f, copy base| {
4545
unsafe {

src/libstd/set.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/libstd/uv_ll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ unsafe fn ip4_name(src: &sockaddr_in) -> ~str {
825825
// ipv4 addr max size: 15 + 1 trailing null byte
826826
let dst: ~[u8] = ~[0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
827827
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8];
828-
do vec::as_buf(dst) |dst_buf, size| {
828+
do vec::as_imm_buf(dst) |dst_buf, size| {
829829
rustrt::rust_uv_ip4_name(to_unsafe_ptr(src),
830830
dst_buf, size as libc::size_t);
831831
// seems that checking the result of uv_ip4_name
@@ -845,7 +845,7 @@ unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
845845
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
846846
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
847847
0u8,0u8,0u8,0u8,0u8,0u8];
848-
do vec::as_buf(dst) |dst_buf, size| {
848+
do vec::as_imm_buf(dst) |dst_buf, size| {
849849
let src_unsafe_ptr = to_unsafe_ptr(src);
850850
log(debug, fmt!("val of src *sockaddr_in6: %? sockaddr_in6: %?",
851851
src_unsafe_ptr, src));

src/rustc/middle/trans/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ fn Call(cx: block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
679679
val_str(cx.ccx().tn, Fn),
680680
Args.map(|arg| val_str(cx.ccx().tn, arg)));
681681
682-
do vec::as_buf(Args) |ptr, len| {
682+
do vec::as_imm_buf(Args) |ptr, len| {
683683
llvm::LLVMBuildCall(B(cx), Fn, ptr, len as c_uint, noname())
684684
}
685685
}

src/rustc/middle/trans/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,13 +1057,13 @@ fn C_zero_byte_arr(size: uint) -> ValueRef unsafe {
10571057
}
10581058
10591059
fn C_struct(elts: &[ValueRef]) -> ValueRef {
1060-
do vec::as_buf(elts) |ptr, len| {
1060+
do vec::as_imm_buf(elts) |ptr, len| {
10611061
llvm::LLVMConstStruct(ptr, len as c_uint, False)
10621062
}
10631063
}
10641064
10651065
fn C_named_struct(T: TypeRef, elts: &[ValueRef]) -> ValueRef {
1066-
do vec::as_buf(elts) |ptr, len| {
1066+
do vec::as_imm_buf(elts) |ptr, len| {
10671067
llvm::LLVMConstNamedStruct(T, ptr, len as c_uint)
10681068
}
10691069
}

src/rustc/middle/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn const_deref(cx: @crate_ctxt, v: ValueRef) -> ValueRef {
6060
}
6161

6262
fn const_get_elt(cx: @crate_ctxt, v: ValueRef, us: &[c_uint]) -> ValueRef {
63-
let r = do vec::as_buf(us) |p, len| {
63+
let r = do vec::as_imm_buf(us) |p, len| {
6464
llvm::LLVMConstExtractValue(v, p, len as c_uint)
6565
};
6666

src/rustc/middle/trans/foreign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] {
7676
fn struct_tys(ty: TypeRef) -> ~[TypeRef] {
7777
let n = llvm::LLVMCountStructElementTypes(ty);
7878
let elts = vec::from_elem(n as uint, ptr::null());
79-
do vec::as_buf(elts) |buf, _len| {
79+
do vec::as_imm_buf(elts) |buf, _len| {
8080
llvm::LLVMGetStructElementTypes(ty, buf);
8181
}
8282
return elts;

0 commit comments

Comments
 (0)