diff --git a/doc/tutorial.md b/doc/tutorial.md index a3c17d6b869e6..f487398d19c23 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -2046,7 +2046,7 @@ trait Seq { } impl Seq for ~[T] { - fn len(&self) -> uint { vec::len(*self) } + fn len(&self) -> uint { self.len() } fn iter(&self, b: &fn(v: &T)) { for vec::each(*self) |elt| { b(elt); } } diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index c40cec262f822..7a0622d059d0c 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -97,7 +97,7 @@ pub fn parse_config(args: ~[~str]) -> config { mode: str_mode(getopts::opt_str(matches, "mode")), run_ignored: getopts::opt_present(matches, "ignored"), filter: - if vec::len(matches.free) > 0u { + if !matches.free.is_empty() { option::Some(copy matches.free[0]) } else { option::None }, logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)), diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 1015373d7ce9e..b4a20886ad866 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -297,7 +297,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { fn check_error_patterns(props: &TestProps, testfile: &Path, ProcRes: &ProcRes) { - if vec::is_empty(props.error_patterns) { + if props.error_patterns.is_empty() { fatal(~"no error pattern specified in " + testfile.to_str()); } diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index 09e6a849f98b5..233c804264009 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -179,7 +179,7 @@ pub mod reader { } pub fn Doc(data: @~[u8]) -> Doc { - Doc { data: data, start: 0u, end: vec::len::(*data) } + Doc { data: data, start: 0u, end: data.len() } } pub fn doc_at(data: @~[u8], start: uint) -> TaggedDoc { diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index eb5699df77f6d..2bc0a8ef6b09f 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -427,7 +427,7 @@ pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] { /// Returns the string argument supplied to a matching option or none pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> { let vals = opt_vals(mm, nm); - if vec::len::(vals) == 0u { return None::<~str>; } + if vals.is_empty() { return None::<~str>; } return match vals[0] { Val(ref s) => Some(copy *s), _ => None @@ -444,7 +444,7 @@ pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> { */ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> { let vals = opt_vals(mm, nm); - if vec::len::(vals) == 0u { return None::<~str>; } + if vals.is_empty() { return None::<~str>; } return match vals[0] { Val(ref s) => Some::<~str>(copy *s), _ => Some::<~str>(str::to_owned(def)) } } diff --git a/src/libextra/sha1.rs b/src/libextra/sha1.rs index a845d32614286..3ad2e727a5d17 100644 --- a/src/libextra/sha1.rs +++ b/src/libextra/sha1.rs @@ -195,7 +195,7 @@ pub fn sha1() -> @Sha1 { * can be assumed that the message digest has been computed. */ fn pad_msg(st: &mut Sha1State) { - assert_eq!(vec::len((*st).msg_block), msg_block_len); + assert_eq!((*st).msg_block.len(), msg_block_len); /* * Check to see if the current message block is too small to hold @@ -368,8 +368,8 @@ mod tests { ]; let tests = fips_180_1_tests + wikipedia_tests; fn check_vec_eq(v0: ~[u8], v1: ~[u8]) { - assert_eq!(vec::len::(v0), vec::len::(v1)); - let len = vec::len::(v0); + assert_eq!(v0.len(), v1.len()); + let len = v0.len(); let mut i = 0u; while i < len { let a = v0[i]; diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index 26d1e28e12252..0189e0db6d4ef 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -15,7 +15,6 @@ use core::prelude::*; use core::cmp::{Eq, Ord}; use core::uint; use core::util::swap; -use core::vec::len; use core::vec; type Le<'self, T> = &'self fn(v1: &T, v2: &T) -> bool; @@ -29,7 +28,7 @@ type Le<'self, T> = &'self fn(v1: &T, v2: &T) -> bool; pub fn merge_sort(v: &[T], le: Le) -> ~[T] { type Slice = (uint, uint); - return merge_sort_(v, (0u, len(v)), le); + return merge_sort_(v, (0u, v.len()), le); fn merge_sort_(v: &[T], slice: Slice, le: Le) -> ~[T] { @@ -47,10 +46,10 @@ pub fn merge_sort(v: &[T], le: Le) -> ~[T] { } fn merge(le: Le, a: &[T], b: &[T]) -> ~[T] { - let mut rs = vec::with_capacity(len(a) + len(b)); - let a_len = len(a); + let mut rs = vec::with_capacity(a.len() + b.len()); + let a_len = a.len(); let mut a_ix = 0; - let b_len = len(b); + let b_len = b.len(); let mut b_ix = 0; while a_ix < a_len && b_ix < b_len { if le(&a[a_ix], &b[b_ix]) { @@ -100,8 +99,9 @@ fn qsort(arr: &mut [T], left: uint, * This is an unstable sort. */ pub fn quick_sort(arr: &mut [T], compare_func: Le) { - if len::(arr) == 0u { return; } - qsort::(arr, 0u, len::(arr) - 1u, compare_func); + let len = arr.len(); + if len == 0u { return; } + qsort::(arr, 0u, len - 1u, compare_func); } fn qsort3(arr: &mut [T], left: int, right: int) { @@ -138,7 +138,7 @@ fn qsort3(arr: &mut [T], left: int, right: int) { vec::swap(arr, k as uint, j as uint); k += 1; j -= 1; - if k == len::(arr) as int { break; } + if k == arr.len() as int { break; } } k = right - 1; while k > q { @@ -754,7 +754,7 @@ mod test_qsort3 { use core::vec; fn check_sort(v1: &mut [int], v2: &mut [int]) { - let len = vec::len::(v1); + let len = v1.len(); quick_sort3::(v1); let mut i = 0; while i < len { @@ -799,7 +799,7 @@ mod test_qsort { use core::vec; fn check_sort(v1: &mut [int], v2: &mut [int]) { - let len = vec::len::(v1); + let len = v1.len(); fn leual(a: &int, b: &int) -> bool { *a <= *b } quick_sort::(v1, leual); let mut i = 0u; @@ -864,7 +864,7 @@ mod tests { use core::vec; fn check_sort(v1: &[int], v2: &[int]) { - let len = vec::len::(v1); + let len = v1.len(); pub fn le(a: &int, b: &int) -> bool { *a <= *b } let f = le; let v3 = merge_sort::(v1, f); @@ -951,7 +951,7 @@ mod test_tim_sort { } fn check_sort(v1: &mut [int], v2: &mut [int]) { - let len = vec::len::(v1); + let len = v1.len(); tim_sort::(v1); let mut i = 0u; while i < len { diff --git a/src/libextra/uv_ll.rs b/src/libextra/uv_ll.rs index 2522f149bf40a..17f1cd499b08a 100644 --- a/src/libextra/uv_ll.rs +++ b/src/libextra/uv_ll.rs @@ -988,7 +988,7 @@ pub unsafe fn accept(server: *libc::c_void, client: *libc::c_void) pub unsafe fn write(req: *uv_write_t, stream: *T, buf_in: *~[uv_buf_t], cb: *u8) -> libc::c_int { let buf_ptr = vec::raw::to_ptr(*buf_in); - let buf_cnt = vec::len(*buf_in) as i32; + let buf_cnt = (*buf_in).len() as i32; return rust_uv_write(req as *libc::c_void, stream as *libc::c_void, buf_ptr, buf_cnt, cb); diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index c6410d16c7429..4e285e686df52 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -624,7 +624,7 @@ pub fn check_roundtrip_convergence(code: @~str, maxIters: uint) { } pub fn check_convergence(files: &[Path]) { - error!("pp convergence tests: %u files", vec::len(files)); + error!("pp convergence tests: %u files", files.len()); for files.each |file| { if !file_might_not_converge(file) { let s = @result::get(&io::read_whole_file_str(file)); @@ -689,7 +689,7 @@ pub fn check_variants(files: &[Path], cx: Context) { pub fn main() { let args = os::args(); - if vec::len(args) != 2u { + if args.len() != 2u { error!("usage: %s ", args[0]); return; } diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 5d0de5356299c..c05e2a85bc708 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -203,8 +203,7 @@ fn is_test_fn(cx: @mut TestCtxt, i: @ast::item) -> bool { } fn is_bench_fn(i: @ast::item) -> bool { - let has_bench_attr = - vec::len(attr::find_attrs_by_name(i.attrs, "bench")) > 0u; + let has_bench_attr = !attr::find_attrs_by_name(i.attrs, "bench").is_empty(); fn has_test_signature(i: @ast::item) -> bool { match i.node { @@ -242,7 +241,7 @@ fn is_ignored(cx: @mut TestCtxt, i: @ast::item) -> bool { } fn should_fail(i: @ast::item) -> bool { - vec::len(attr::find_attrs_by_name(i.attrs, "should_fail")) > 0u + !attr::find_attrs_by_name(i.attrs, "should_fail").is_empty() } fn add_test_module(cx: &TestCtxt, m: &ast::_mod) -> ast::_mod { diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 1ebf8f2e9f471..2017c29590cbe 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -212,7 +212,7 @@ fn get_metadata_section(os: os, let mut found = None; unsafe { let cvbuf: *u8 = cast::transmute(cbuf); - let vlen = vec::len(encoder::metadata_encoding_version); + let vlen = encoder::metadata_encoding_version.len(); debug!("checking %u bytes of metadata-version stamp", vlen); let minsz = uint::min(vlen, csz); diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 98f8efb72c80f..c95ff49e53cd5 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -786,7 +786,7 @@ pub fn check_fn(cx: @MatchCheckCtxt, pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool { match cx.tcx.def_map.find(&pat.id) { Some(&def_variant(enum_id, _)) => { - if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u { + if ty::enum_variants(cx.tcx, enum_id).len() != 1u { return true; } } diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 7a57f78d60bb9..abce35bebffb4 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -119,5 +119,5 @@ pub fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info { } pub fn has_freevars(tcx: ty::ctxt, fid: ast::node_id) -> bool { - return vec::len(*get_freevars(tcx, fid)) != 0u; + !get_freevars(tcx, fid).is_empty() } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 543264ba11ed0..f1938129b0601 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -348,7 +348,7 @@ fn is_nullary_variant(cx: Context, ex: @expr) -> bool { expr_path(_) => { match cx.tcx.def_map.get_copy(&ex.id) { def_variant(edid, vdid) => { - vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u + ty::enum_variant_with_id(cx.tcx, edid, vdid).args.is_empty() } _ => false } diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index a77e27bf0fe41..3b26a2cbf2246 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -53,14 +53,13 @@ pub fn count_insn(cx: block, category: &str) { // Pass 1: scan table mapping str -> rightmost pos. let mut mm = HashMap::new(); - let len = vec::len(*v); + let len = v.len(); let mut i = 0u; while i < len { mm.insert(copy v[i], i); i += 1u; } - // Pass 2: concat strings for each elt, skipping // forwards over any cycles by advancing to rightmost // occurrence of each element in path. diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 962198e38d5a8..ae3adce0c0e0b 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2373,7 +2373,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { ty_enum(did, ref substs) => { seen.push(did); let vs = enum_variants(cx, did); - let r = vec::len(*vs) > 0u && do vs.iter().all |variant| { + let r = !vs.is_empty() && do vs.iter().all |variant| { do variant.args.iter().any |aty| { let sty = subst(cx, substs, *aty); type_requires(cx, seen, r_ty, sty) diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs index c2ee7fc2647bd..ab52ef36978a5 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/typeck/infer/resolve.rs @@ -113,9 +113,9 @@ impl ResolveState { // n.b. This is a hokey mess because the current fold doesn't // allow us to pass back errors in any useful way. - assert!(vec::is_empty(self.v_seen)); + assert!(self.v_seen.is_empty()); let rty = indent(|| self.resolve_type(typ) ); - assert!(vec::is_empty(self.v_seen)); + assert!(self.v_seen.is_empty()); match self.err { None => { debug!("Resolved to %s + %s (modes=%x)", diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 0d26e4c6ef1e6..adb0f43e2d720 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -279,7 +279,7 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) { version(*binary); return; } - let input = match vec::len(matches.free) { + let input = match matches.free.len() { 0u => early_error(demitter, ~"no input filename given"), 1u => { let ifile = /*bad*/copy matches.free[0]; diff --git a/src/librustdoc/astsrv.rs b/src/librustdoc/astsrv.rs index c4fc377bc8bf7..74a403ff7412d 100644 --- a/src/librustdoc/astsrv.rs +++ b/src/librustdoc/astsrv.rs @@ -141,7 +141,7 @@ fn should_prune_unconfigured_items() { let source = ~"#[cfg(shut_up_and_leave_me_alone)]fn a() { }"; do from_str(source) |srv| { do exec(srv) |ctxt| { - assert!(vec::is_empty(ctxt.ast.node.module.items)); + assert!(ctxt.ast.node.module.items.is_empty()); } } } diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs index 1175175c2d6b9..73956df954239 100644 --- a/src/librustdoc/extract.rs +++ b/src/librustdoc/extract.rs @@ -295,8 +295,8 @@ mod test { #[test] fn extract_empty_crate() { let doc = mk_doc(~""); - assert!(vec::is_empty(doc.cratemod().mods())); - assert!(vec::is_empty(doc.cratemod().fns())); + assert!(doc.cratemod().mods().is_empty()); + assert!(doc.cratemod().fns().is_empty()); } #[test] diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index b17816d4e3652..7d41b899bc3d5 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -343,7 +343,7 @@ fn item_header_lvl(doc: &doc::ItemTag) -> Hlvl { } fn write_index(ctxt: &Ctxt, index: &doc::Index) { - if vec::is_empty(index.entries) { + if index.entries.is_empty() { return; } @@ -437,7 +437,7 @@ fn write_variants( ctxt: &Ctxt, docs: &[doc::VariantDoc] ) { - if vec::is_empty(docs) { + if docs.is_empty() { return; } diff --git a/src/librustdoc/page_pass.rs b/src/librustdoc/page_pass.rs index 29a6765f16d53..bb5d71e8db168 100644 --- a/src/librustdoc/page_pass.rs +++ b/src/librustdoc/page_pass.rs @@ -191,6 +191,6 @@ mod test { #[test] fn should_remove_mods_from_containing_mods() { let doc = mk_doc(~"mod a { }"); - assert!(vec::is_empty(doc.cratemod().mods())); + assert!(doc.cratemod().mods().is_empty()); } } diff --git a/src/librustdoc/prune_hidden_pass.rs b/src/librustdoc/prune_hidden_pass.rs index c7fe29b3296e6..8a90d3f74d390 100644 --- a/src/librustdoc/prune_hidden_pass.rs +++ b/src/librustdoc/prune_hidden_pass.rs @@ -80,6 +80,6 @@ mod test { use core::vec; let doc = mk_doc(~"#[doc(hidden)] mod a { }"); - assert!(vec::is_empty(doc.cratemod().mods())) + assert!(doc.cratemod().mods().is_empty()) } } diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index a2fa80daa3ba2..e861939c2dde7 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -175,7 +175,7 @@ mod test { #[test] fn should_prune_items_without_pub_modifier() { let doc = mk_doc(~"mod a { }"); - assert!(vec::is_empty(doc.cratemod().mods())); + assert!(doc.cratemod().mods().is_empty()); } #[test] diff --git a/src/librustdoc/sectionalize_pass.rs b/src/librustdoc/sectionalize_pass.rs index 1a475879fc10b..75f8e22f67e13 100644 --- a/src/librustdoc/sectionalize_pass.rs +++ b/src/librustdoc/sectionalize_pass.rs @@ -217,7 +217,7 @@ mod test { Body\"]\ mod a { }"); - assert!(vec::is_empty(doc.cratemod().mods()[0].item.sections)); + assert!(doc.cratemod().mods()[0].item.sections.is_empty()); } #[test] diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 8f7a0015bcf15..24751b66925e6 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -20,6 +20,7 @@ use option::{None, Option, Some}; use old_iter::BaseIter; use vec; use vec::OwnedVector; +use container::Container; /// The result type #[deriving(Clone, Eq)] @@ -301,7 +302,7 @@ impl Result { pub fn map_vec( ts: &[T], op: &fn(&T) -> Result) -> Result<~[V],U> { - let mut vs: ~[V] = vec::with_capacity(vec::len(ts)); + let mut vs: ~[V] = vec::with_capacity(ts.len()); for ts.each |t| { match op(t) { Ok(v) => vs.push(v), @@ -339,7 +340,7 @@ pub fn map_vec2(ss: &[S], ts: &[T], op: &fn(&S,&T) -> Result) -> Result<~[V],U> { assert!(vec::same_length(ss, ts)); - let n = vec::len(ts); + let n = ts.len(); let mut vs = vec::with_capacity(n); let mut i = 0u; while i < n { @@ -362,7 +363,7 @@ pub fn iter_vec2(ss: &[S], ts: &[T], op: &fn(&S,&T) -> Result<(),U>) -> Result<(),U> { assert!(vec::same_length(ss, ts)); - let n = vec::len(ts); + let n = ts.len(); let mut i = 0u; while i < n { match op(&ss[i],&ts[i]) { diff --git a/src/libstd/str.rs b/src/libstd/str.rs index f9d1116499586..2af300fc1b881 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1752,7 +1752,7 @@ Section: Misc /// Determines if a vector of bytes contains valid UTF-8 pub fn is_utf8(v: &const [u8]) -> bool { let mut i = 0u; - let total = vec::len::(v); + let total = v.len(); while i < total { let mut chsize = utf8_char_width(v[i]); if chsize == 0u { return false; } @@ -3693,7 +3693,7 @@ mod tests { let s2: ~str = from_bytes(v); let mut i: uint = 0u; let n1: uint = len(s1); - let n2: uint = vec::len::(v); + let n2: uint = v.len(); assert_eq!(n1, n2); while i < n1 { let a: u8 = s1[i]; diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 7c52ccc967ebb..19233c533481e 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -56,11 +56,6 @@ pub mod rustrt { } } -/// Returns true if a vector contains no elements -pub fn is_empty(v: &const [T]) -> bool { - as_const_buf(v, |_p, len| len == 0u) -} - /// Returns true if two vectors have the same length pub fn same_length(xs: &const [T], ys: &const [U]) -> bool { xs.len() == ys.len() @@ -123,12 +118,6 @@ pub fn capacity(v: &const ~[T]) -> uint { } } -/// Returns the length of a vector -#[inline(always)] -pub fn len(v: &const [T]) -> uint { - as_const_buf(v, |_p, len| len) -} - // A botch to tide us over until core and std are fully demuted. #[allow(missing_doc)] pub fn uniq_len(v: &const ~[T]) -> uint { @@ -291,7 +280,7 @@ pub fn last_opt<'r,T>(v: &'r [T]) -> Option<&'r T> { #[inline(always)] pub fn slice<'r,T>(v: &'r [T], start: uint, end: uint) -> &'r [T] { assert!(start <= end); - assert!(end <= len(v)); + assert!(end <= v.len()); do as_imm_buf(v) |p, _len| { unsafe { transmute((ptr::offset(p, start), @@ -319,7 +308,7 @@ pub fn mut_slice<'r,T>(v: &'r mut [T], start: uint, end: uint) pub fn const_slice<'r,T>(v: &'r const [T], start: uint, end: uint) -> &'r const [T] { assert!(start <= end); - assert!(end <= len(v)); + assert!(end <= v.len()); do as_const_buf(v) |p, _len| { unsafe { transmute((ptr::const_offset(p, start), @@ -332,7 +321,7 @@ pub fn const_slice<'r,T>(v: &'r const [T], start: uint, end: uint) /// Split the vector `v` by applying each element against the predicate `f`. pub fn split(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { - let ln = len(v); + let ln = v.len(); if (ln == 0u) { return ~[] } let mut start = 0u; @@ -355,7 +344,7 @@ pub fn split(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { * to `n` times. */ pub fn splitn(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { - let ln = len(v); + let ln = v.len(); if (ln == 0u) { return ~[] } let mut start = 0u; @@ -381,7 +370,7 @@ pub fn splitn(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { * `f`. */ pub fn rsplit(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { - let ln = len(v); + let ln = v.len(); if (ln == 0) { return ~[] } let mut end = ln; @@ -405,7 +394,7 @@ pub fn rsplit(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { * `f` up to `n times. */ pub fn rsplitn(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { - let ln = len(v); + let ln = v.len(); if (ln == 0u) { return ~[] } let mut end = ln; @@ -861,7 +850,7 @@ pub fn grow_set(v: &mut ~[T], index: uint, initval: &T, val: T) { /// Apply a function to each element of a vector and return the results pub fn map(v: &[T], f: &fn(t: &T) -> U) -> ~[U] { - let mut result = with_capacity(len(v)); + let mut result = with_capacity(v.len()); for each(v) |elem| { result.push(f(elem)); } @@ -908,8 +897,8 @@ pub fn flat_map(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] { */ pub fn map_zip(v0: &[T], v1: &[U], f: &fn(t: &T, v: &U) -> V) -> ~[V] { - let v0_len = len(v0); - if v0_len != len(v1) { fail!(); } + let v0_len = v0.len(); + if v0_len != v1.len() { fail!(); } let mut u: ~[V] = ~[]; let mut i = 0u; while i < v0_len { @@ -1080,7 +1069,7 @@ pub fn contains(v: &[T], x: &T) -> bool { * is returned. If `f` matches no elements then none is returned. */ pub fn find(v: &[T], f: &fn(t: &T) -> bool) -> Option { - find_between(v, 0u, len(v), f) + find_between(v, 0u, v.len(), f) } /** @@ -1103,7 +1092,7 @@ pub fn find_between(v: &[T], start: uint, end: uint, * matches no elements then none is returned. */ pub fn rfind(v: &[T], f: &fn(t: &T) -> bool) -> Option { - rfind_between(v, 0u, len(v), f) + rfind_between(v, 0u, v.len(), f) } /** @@ -1134,7 +1123,7 @@ pub fn position_elem(v: &[T], x: &T) -> Option { * then none is returned. */ pub fn position(v: &[T], f: &fn(t: &T) -> bool) -> Option { - position_between(v, 0u, len(v), f) + position_between(v, 0u, v.len(), f) } /** @@ -1150,7 +1139,7 @@ pub fn position_between(v: &[T], f: &fn(t: &T) -> bool) -> Option { assert!(start <= end); - assert!(end <= len(v)); + assert!(end <= v.len()); let mut i = start; while i < end { if f(&v[i]) { return Some::(i); } i += 1u; } None @@ -1169,7 +1158,7 @@ pub fn rposition_elem(v: &[T], x: &T) -> Option { * matches no elements then none is returned. */ pub fn rposition(v: &[T], f: &fn(t: &T) -> bool) -> Option { - rposition_between(v, 0u, len(v), f) + rposition_between(v, 0u, v.len(), f) } /** @@ -1183,7 +1172,7 @@ pub fn rposition(v: &[T], f: &fn(t: &T) -> bool) -> Option { pub fn rposition_between(v: &[T], start: uint, end: uint, f: &fn(t: &T) -> bool) -> Option { assert!(start <= end); - assert!(end <= len(v)); + assert!(end <= v.len()); let mut i = end; while i > start { if f(&v[i - 1u]) { return Some::(i - 1u); } @@ -1273,9 +1262,9 @@ pub fn unzip(v: ~[(T, U)]) -> (~[T], ~[U]) { pub fn zip_slice(v: &const [T], u: &const [U]) -> ~[(T, U)] { let mut zipped = ~[]; - let sz = len(v); + let sz = v.len(); let mut i = 0u; - assert_eq!(sz, len(u)); + assert_eq!(sz, u.len()); while i < sz { zipped.push((v[i], u[i])); i += 1u; @@ -1290,8 +1279,8 @@ pub fn zip_slice(v: &const [T], u: &const [U]) * i-th elements from each of the input vectors. */ pub fn zip(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] { - let mut i = len(v); - assert_eq!(i, len(u)); + let mut i = v.len(); + assert_eq!(i, u.len()); let mut w = with_capacity(i); while i > 0 { w.push((v.pop(),u.pop())); @@ -1324,7 +1313,7 @@ pub fn swap(v: &mut [T], a: uint, b: uint) { /// Reverse the order of elements in a vector, in place pub fn reverse(v: &mut [T]) { let mut i: uint = 0; - let ln = len::(v); + let ln = v.len(); while i < ln / 2 { swap(v, i, ln - i - 1); i += 1; @@ -1372,7 +1361,7 @@ pub fn reverse_part(v: &mut [T], start: uint, end : uint) { /// Returns a vector with the order of elements reversed pub fn reversed(v: &const [T]) -> ~[T] { let mut rs: ~[T] = ~[]; - let mut i = len::(v); + let mut i = v.len(); if i == 0 { return (rs); } else { i -= 1; } while i != 0 { rs.push(v[i]); i -= 1; } rs.push(v[0]); @@ -1479,7 +1468,7 @@ pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool { * of elements in `v` (so if `v` is sorted then the permutations are * lexicographically sorted). * - * The total number of permutations produced is `len(v)!`. If `v` contains + * The total number of permutations produced is `v.len()!`. If `v` contains * repeated elements, then some permutations are repeated. * * See [Algorithms to generate @@ -1779,11 +1768,16 @@ pub mod traits { impl<'self,T> Container for &'self const [T] { /// Returns true if a vector contains no elements #[inline] - fn is_empty(&const self) -> bool { is_empty(*self) } + fn is_empty(&const self) -> bool { + as_const_buf(*self, |_p, len| len == 0u) + } /// Returns the length of a vector #[inline] - fn len(&const self) -> uint { len(*self) } + fn len(&const self) -> uint { + as_const_buf(*self, |_p, len| len) + } + } #[allow(missing_doc)] @@ -2250,7 +2244,7 @@ pub mod raw { use ptr; use sys; use unstable::intrinsics; - use vec::{UnboxedVecRepr, as_const_buf, as_mut_buf, len, with_capacity}; + use vec::{UnboxedVecRepr, as_const_buf, as_mut_buf, with_capacity}; use util; /// The internal representation of a (boxed) vector @@ -2872,8 +2866,9 @@ mod tests { #[test] fn test_is_empty() { - assert!(is_empty::([])); - assert!(!is_empty([0])); + let xs: [int, ..0] = []; + assert!(xs.is_empty()); + assert!(![0].is_empty()); } #[test] diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index ec77ba8853041..fecded5e87b21 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -66,7 +66,7 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner) } pub fn path_ident_to_str(p: &path, i: ident, itr: @ident_interner) -> ~str { - if vec::is_empty(*p) { + if p.is_empty() { //FIXME /* FIXME (#2543) */ copy *i copy *itr.get(i.name) } else { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8ebb7de0bfe64..59db35201f100 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2768,7 +2768,7 @@ impl Parser { attributes_box.push_all(self.parse_outer_attributes()); match *self.token { token::SEMI => { - if !vec::is_empty(attributes_box) { + if !attributes_box.is_empty() { self.span_err(*self.last_span, "expected item after attributes"); attributes_box = ~[]; } @@ -2839,7 +2839,7 @@ impl Parser { } } - if !vec::is_empty(attributes_box) { + if !attributes_box.is_empty() { self.span_err(*self.last_span, "expected item after attributes"); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index e871ee5c9bf88..5c81d406cd200 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2041,7 +2041,7 @@ pub fn lit_to_str(l: @ast::lit) -> ~str { pub fn next_lit(s: @ps, pos: BytePos) -> Option { match s.literals { Some(ref lits) => { - while s.cur_cmnt_and_lit.cur_lit < vec::len((*lits)) { + while s.cur_cmnt_and_lit.cur_lit < lits.len() { let ltrl = /*bad*/ copy (*lits)[s.cur_cmnt_and_lit.cur_lit]; if ltrl.pos > pos { return None; } s.cur_cmnt_and_lit.cur_lit += 1u; @@ -2128,7 +2128,7 @@ pub fn to_str(t: T, f: @fn(@ps, T), intr: @ident_interner) -> ~str { pub fn next_comment(s: @ps) -> Option { match s.comments { Some(ref cmnts) => { - if s.cur_cmnt_and_lit.cur_cmnt < vec::len((*cmnts)) { + if s.cur_cmnt_and_lit.cur_cmnt < cmnts.len() { return Some(copy cmnts[s.cur_cmnt_and_lit.cur_cmnt]); } else { return None::; } } diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index c0e147b2db556..020b53b9d9ae1 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -40,7 +40,7 @@ fn send(p: &pipe, msg: uint) { fn recv(p: &pipe) -> uint { unsafe { do p.access_cond |state, cond| { - while vec::is_empty(*state) { + while state.is_empty() { cond.wait(); } state.pop() diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 9aaf565f36834..f2fe45ac5bdbe 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -37,7 +37,7 @@ fn send(p: &pipe, msg: uint) { } fn recv(p: &pipe) -> uint { do p.write_cond |state, cond| { - while vec::is_empty(*state) { + while state.is_empty() { cond.wait(); } state.pop() diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 3cff8baa82928..9f125a48de956 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -64,7 +64,7 @@ fn select_random(r: u32, genelist: ~[AminoAcids]) -> char { } else { return bisect(v, mid, hi, target); } } else { return v[hi].ch; } } - return bisect(copy genelist, 0, vec::len::(genelist) - 1, r); + return bisect(copy genelist, 0, genelist.len() - 1, r); } fn make_random_fasta(wr: @io::Writer, diff --git a/src/test/run-pass/import-in-block.rs b/src/test/run-pass/import-in-block.rs index 9537162e1c803..b423073eca721 100644 --- a/src/test/run-pass/import-in-block.rs +++ b/src/test/run-pass/import-in-block.rs @@ -9,10 +9,12 @@ // except according to those terms. pub fn main() { - use std::vec::from_fn; - debug!(::std::vec::len(from_fn(2, |i| i))); + use std::util::replace; + let mut x = 5; + replace(&mut x, 6); { - use std::vec::*; - debug!(len(~[2])); + use std::util::*; + let mut y = 6; + swap(&mut x, &mut y); } } diff --git a/src/test/run-pass/mutable-alias-vec.rs b/src/test/run-pass/mutable-alias-vec.rs index 91f4fdb01f638..1d9e7d3c64966 100644 --- a/src/test/run-pass/mutable-alias-vec.rs +++ b/src/test/run-pass/mutable-alias-vec.rs @@ -20,7 +20,7 @@ pub fn main() { grow(&mut v); grow(&mut v); grow(&mut v); - let len = vec::len::(v); + let len = v.len(); debug!(len); assert_eq!(len, 3 as uint); } diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 46457f667aed4..3d3f1404dc2a5 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -47,7 +47,7 @@ trait vec_utils { } impl vec_utils for ~[T] { - fn length_(&self) -> uint { vec::len(*self) } + fn length_(&self) -> uint { self.len() } fn iter_(&self, f: &fn(&T)) { for self.each |x| { f(x); } } fn map_(&self, f: &fn(&T) -> U) -> ~[U] { let mut r = ~[]; diff --git a/src/test/run-pass/utf8_chars.rs b/src/test/run-pass/utf8_chars.rs index 2343949f049a6..0069165aed4ef 100644 --- a/src/test/run-pass/utf8_chars.rs +++ b/src/test/run-pass/utf8_chars.rs @@ -20,7 +20,7 @@ pub fn main() { assert!(str::len(s) == 10u); assert!(str::char_len(s) == 4u); - assert!(vec::len(str::to_chars(s)) == 4u); + assert!(str::to_chars(s).len() == 4u); assert!(str::from_chars(str::to_chars(s)) == s); assert!(str::char_at(s, 0u) == 'e'); assert!(str::char_at(s, 1u) == 'é');