Skip to content

Commit cdea73c

Browse files
committed
Convert vec::{as_imm_buf, as_mut_buf} to methods.
1 parent a732a2d commit cdea73c

File tree

14 files changed

+90
-86
lines changed

14 files changed

+90
-86
lines changed

src/libextra/flate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static LZ_NORM : c_int = 0x80; // LZ with 128 probes, "normal"
4545
static LZ_BEST : c_int = 0xfff; // LZ with 4095 probes, "best"
4646

4747
pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
48-
do vec::as_imm_buf(bytes) |b, len| {
48+
do bytes.as_imm_buf |b, len| {
4949
unsafe {
5050
let mut outsz : size_t = 0;
5151
let res =
@@ -63,7 +63,7 @@ pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
6363
}
6464

6565
pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] {
66-
do vec::as_imm_buf(bytes) |b, len| {
66+
do bytes.as_imm_buf |b, len| {
6767
unsafe {
6868
let mut outsz : size_t = 0;
6969
let res =

src/libextra/par.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn map_slices<A:Copy + Send,B:Copy + Send>(
5353
info!("spawning tasks");
5454
while base < len {
5555
let end = uint::min(len, base + items_per_task);
56-
do vec::as_imm_buf(xs) |p, _len| {
56+
do xs.as_imm_buf |p, _len| {
5757
let f = f();
5858
let base = base;
5959
let f = do future_spawn() || {

src/libextra/uv_ll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ pub unsafe fn ip4_name(src: &sockaddr_in) -> ~str {
10461046
// ipv4 addr max size: 15 + 1 trailing null byte
10471047
let dst: ~[u8] = ~[0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
10481048
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8];
1049-
do vec::as_imm_buf(dst) |dst_buf, size| {
1049+
do dst.as_imm_buf |dst_buf, size| {
10501050
rust_uv_ip4_name(to_unsafe_ptr(src),
10511051
dst_buf, size as libc::size_t);
10521052
// seems that checking the result of uv_ip4_name
@@ -1066,7 +1066,7 @@ pub unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
10661066
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
10671067
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
10681068
0u8,0u8,0u8,0u8,0u8,0u8];
1069-
do vec::as_imm_buf(dst) |dst_buf, size| {
1069+
do dst.as_imm_buf |dst_buf, size| {
10701070
let src_unsafe_ptr = to_unsafe_ptr(src);
10711071
let result = rust_uv_ip6_name(src_unsafe_ptr,
10721072
dst_buf, size as libc::size_t);

src/librustc/middle/trans/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,
565565
let min = llvm::LLVMConstInt(t, lo, signed);
566566
let max = llvm::LLVMConstInt(t, hi, signed);
567567

568-
do vec::as_imm_buf([min, max]) |ptr, len| {
568+
do [min, max].as_imm_buf |ptr, len| {
569569
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
570570
llvm::LLVMMDNodeInContext(cx.fcx.ccx.llcx,
571571
ptr, len as c_uint));
@@ -942,7 +942,7 @@ pub fn Call(cx: block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
942942
cx.val_to_str(Fn),
943943
Args.map(|arg| cx.val_to_str(*arg)));
944944

945-
do vec::as_imm_buf(Args) |ptr, len| {
945+
do Args.as_imm_buf |ptr, len| {
946946
llvm::LLVMBuildCall(B(cx), Fn, ptr, len as c_uint, noname())
947947
}
948948
}

src/librustc/middle/trans/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,23 +774,23 @@ pub fn C_zero_byte_arr(size: uint) -> ValueRef {
774774

775775
pub fn C_struct(elts: &[ValueRef]) -> ValueRef {
776776
unsafe {
777-
do vec::as_imm_buf(elts) |ptr, len| {
777+
do elts.as_imm_buf |ptr, len| {
778778
llvm::LLVMConstStructInContext(base::task_llcx(), ptr, len as c_uint, False)
779779
}
780780
}
781781
}
782782

783783
pub fn C_packed_struct(elts: &[ValueRef]) -> ValueRef {
784784
unsafe {
785-
do vec::as_imm_buf(elts) |ptr, len| {
785+
do elts.as_imm_buf |ptr, len| {
786786
llvm::LLVMConstStructInContext(base::task_llcx(), ptr, len as c_uint, True)
787787
}
788788
}
789789
}
790790

791791
pub fn C_named_struct(T: Type, elts: &[ValueRef]) -> ValueRef {
792792
unsafe {
793-
do vec::as_imm_buf(elts) |ptr, len| {
793+
do elts.as_imm_buf |ptr, len| {
794794
llvm::LLVMConstNamedStruct(T.to_ref(), ptr, len as c_uint)
795795
}
796796
}
@@ -826,7 +826,7 @@ pub fn get_param(fndecl: ValueRef, param: uint) -> ValueRef {
826826
pub fn const_get_elt(cx: &CrateContext, v: ValueRef, us: &[c_uint])
827827
-> ValueRef {
828828
unsafe {
829-
let r = do vec::as_imm_buf(us) |p, len| {
829+
let r = do us.as_imm_buf |p, len| {
830830
llvm::LLVMConstExtractValue(v, p, len as c_uint)
831831
};
832832

src/libstd/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ fn convert_whence(whence: SeekStyle) -> i32 {
917917
impl Reader for *libc::FILE {
918918
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
919919
unsafe {
920-
do vec::as_mut_buf(bytes) |buf_p, buf_len| {
920+
do bytes.as_mut_buf |buf_p, buf_len| {
921921
assert!(buf_len >= len);
922922

923923
let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
@@ -1152,7 +1152,7 @@ impl<W:Writer,C> Writer for Wrapper<W, C> {
11521152
impl Writer for *libc::FILE {
11531153
fn write(&self, v: &[u8]) {
11541154
unsafe {
1155-
do vec::as_imm_buf(v) |vbuf, len| {
1155+
do v.as_imm_buf |vbuf, len| {
11561156
let nout = libc::fwrite(vbuf as *c_void,
11571157
1,
11581158
len as size_t,
@@ -1203,7 +1203,7 @@ impl Writer for fd_t {
12031203
fn write(&self, v: &[u8]) {
12041204
unsafe {
12051205
let mut count = 0u;
1206-
do vec::as_imm_buf(v) |vbuf, len| {
1206+
do v.as_imm_buf |vbuf, len| {
12071207
while count < len {
12081208
let vb = ptr::offset(vbuf, count) as *c_void;
12091209
let nout = libc::write(*self, vb, len as size_t);

src/libstd/os.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn as_c_charp<T>(s: &str, f: &fn(*c_char) -> T) -> T {
9292
pub fn fill_charp_buf(f: &fn(*mut c_char, size_t) -> bool)
9393
-> Option<~str> {
9494
let mut buf = vec::from_elem(TMPBUF_SZ, 0u8 as c_char);
95-
do vec::as_mut_buf(buf) |b, sz| {
95+
do buf.as_mut_buf |b, sz| {
9696
if f(b, sz as size_t) {
9797
unsafe {
9898
Some(str::raw::from_buf(b as *u8))
@@ -122,7 +122,7 @@ pub mod win32 {
122122
while !done {
123123
let mut k: DWORD = 0;
124124
let mut buf = vec::from_elem(n as uint, 0u16);
125-
do vec::as_mut_buf(buf) |b, _sz| {
125+
do buf.as_mut_buf |b, _sz| {
126126
k = f(b, TMPBUF_SZ as DWORD);
127127
if k == (0 as DWORD) {
128128
done = true;
@@ -147,7 +147,7 @@ pub mod win32 {
147147
let mut t = s.to_utf16();
148148
// Null terminate before passing on.
149149
t.push(0u16);
150-
vec::as_imm_buf(t, |buf, _len| f(buf))
150+
t.as_imm_buf(|buf, _len| f(buf))
151151
}
152152
}
153153

@@ -937,7 +937,7 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
937937
let mut done = false;
938938
let mut ok = true;
939939
while !done {
940-
do vec::as_mut_buf(buf) |b, _sz| {
940+
do buf.as_mut_buf |b, _sz| {
941941
let nread = libc::fread(b as *mut c_void, 1u as size_t,
942942
bufsize as size_t,
943943
istream);
@@ -1683,7 +1683,7 @@ mod tests {
16831683
let s = ~"hello";
16841684
let mut buf = s.as_bytes_with_null().to_owned();
16851685
let len = buf.len();
1686-
do vec::as_mut_buf(buf) |b, _len| {
1686+
do buf.as_mut_buf |b, _len| {
16871687
assert_eq!(libc::fwrite(b as *c_void, 1u as size_t,
16881688
(s.len() + 1u) as size_t, ostream),
16891689
len as size_t)

src/libstd/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub mod ptr_tests {
406406
do str::as_c_str(s1) |p1| {
407407
do str::as_c_str(s2) |p2| {
408408
let v = ~[p0, p1, p2, null()];
409-
do vec::as_imm_buf(v) |vp, len| {
409+
do v.as_imm_buf |vp, len| {
410410
assert_eq!(unsafe { buf_len(vp) }, 3u);
411411
assert_eq!(len, 4u);
412412
}

src/libstd/rand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ pub fn seed() -> ~[u8] {
830830
unsafe {
831831
let n = rustrt::rand_seed_size() as uint;
832832
let mut s = vec::from_elem(n, 0_u8);
833-
do vec::as_mut_buf(s) |p, sz| {
833+
do s.as_mut_buf |p, sz| {
834834
rustrt::rand_gen_seed(p, sz as size_t)
835835
}
836836
s
@@ -1087,7 +1087,7 @@ mod tests {
10871087
for 10.times {
10881088
unsafe {
10891089
let seed = super::seed();
1090-
let rt_rng = do vec::as_imm_buf(seed) |p, sz| {
1090+
let rt_rng = do seed.as_imm_buf |p, sz| {
10911091
rustrt::rand_new_seeded(p, sz as size_t)
10921092
};
10931093
let mut rng = IsaacRng::new_seeded(seed);

src/libstd/rt/uv/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use str::raw::from_c_str;
4040
use to_str::ToStr;
4141
use ptr::RawPtr;
4242
use vec;
43+
use vec::ImmutableVector;
4344
use ptr;
4445
use str;
4546
use libc::{c_void, c_int, size_t, malloc, free};
@@ -300,7 +301,7 @@ pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
300301
unsafe {
301302
let data = malloc(v.len() as size_t) as *u8;
302303
assert!(data.is_not_null());
303-
do vec::as_imm_buf(v) |b, l| {
304+
do v.as_imm_buf |b, l| {
304305
let data = data as *mut u8;
305306
ptr::copy_memory(data, b, l)
306307
}

src/libstd/run.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use prelude::*;
2424
use ptr;
2525
use str;
2626
use task;
27-
use vec;
27+
use vec::ImmutableVector;
2828

2929
/**
3030
* A value representing a child process.
@@ -703,7 +703,7 @@ fn with_argv<T>(prog: &str, args: &[~str],
703703
argptrs.push(str::as_c_str(*t, |b| b));
704704
}
705705
argptrs.push(ptr::null());
706-
vec::as_imm_buf(argptrs, |buf, _len| cb(buf))
706+
argptrs.as_imm_buf(|buf, _len| cb(buf))
707707
}
708708

709709
#[cfg(unix)]
@@ -722,7 +722,7 @@ fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
722722
}
723723

724724
ptrs.push(ptr::null());
725-
vec::as_imm_buf(ptrs, |p, _len|
725+
ptrs.as_imm_buf(|p, _len|
726726
unsafe { cb(::cast::transmute(p)) }
727727
)
728728
}
@@ -743,7 +743,7 @@ fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T {
743743
blk.push_all(kv.as_bytes_with_null_consume());
744744
}
745745
blk.push(0);
746-
vec::as_imm_buf(blk, |p, _len|
746+
blk.as_imm_buf(|p, _len|
747747
unsafe { cb(::cast::transmute(p)) }
748748
)
749749
}

src/libstd/str.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ pub mod raw {
826826
use str::raw;
827827
use str::{as_buf, is_utf8};
828828
use vec;
829+
use vec::MutableVector;
829830

830831
/// Create a Rust string from a null-terminated *u8 buffer
831832
pub unsafe fn from_buf(buf: *u8) -> ~str {
@@ -841,7 +842,7 @@ pub mod raw {
841842
/// Create a Rust string from a *u8 buffer of the given length
842843
pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str {
843844
let mut v: ~[u8] = vec::with_capacity(len + 1);
844-
vec::as_mut_buf(v, |vbuf, _len| {
845+
v.as_mut_buf(|vbuf, _len| {
845846
ptr::copy_memory(vbuf, buf as *u8, len)
846847
});
847848
vec::raw::set_len(&mut v, len);
@@ -863,7 +864,7 @@ pub mod raw {
863864

864865
/// Converts a vector of bytes to a new owned string.
865866
pub unsafe fn from_bytes(v: &[u8]) -> ~str {
866-
do vec::as_imm_buf(v) |buf, len| {
867+
do v.as_imm_buf |buf, len| {
867868
from_buf_len(buf, len)
868869
}
869870
}
@@ -917,7 +918,7 @@ pub mod raw {
917918
assert!((end <= n));
918919

919920
let mut v = vec::with_capacity(end - begin + 1u);
920-
do vec::as_imm_buf(v) |vbuf, _vlen| {
921+
do v.as_imm_buf |vbuf, _vlen| {
921922
let vbuf = ::cast::transmute_mut_unsafe(vbuf);
922923
let src = ptr::offset(sbuf, begin);
923924
ptr::copy_memory(vbuf, src, end - begin);

0 commit comments

Comments
 (0)