1
Fork 0

remove deprecated vec::{is_empty, len} functions

This commit is contained in:
Daniel Micay 2013-06-08 21:38:47 -04:00
parent 470bf0dfb3
commit de367157b5
38 changed files with 100 additions and 104 deletions

View file

@ -2046,7 +2046,7 @@ trait Seq<T> {
} }
impl<T> Seq<T> for ~[T] { impl<T> Seq<T> for ~[T] {
fn len(&self) -> uint { vec::len(*self) } fn len(&self) -> uint { self.len() }
fn iter(&self, b: &fn(v: &T)) { fn iter(&self, b: &fn(v: &T)) {
for vec::each(*self) |elt| { b(elt); } for vec::each(*self) |elt| { b(elt); }
} }

View file

@ -97,7 +97,7 @@ pub fn parse_config(args: ~[~str]) -> config {
mode: str_mode(getopts::opt_str(matches, "mode")), mode: str_mode(getopts::opt_str(matches, "mode")),
run_ignored: getopts::opt_present(matches, "ignored"), run_ignored: getopts::opt_present(matches, "ignored"),
filter: filter:
if vec::len(matches.free) > 0u { if !matches.free.is_empty() {
option::Some(copy matches.free[0]) option::Some(copy matches.free[0])
} else { option::None }, } else { option::None },
logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)), logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)),

View file

@ -297,7 +297,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
fn check_error_patterns(props: &TestProps, fn check_error_patterns(props: &TestProps,
testfile: &Path, testfile: &Path,
ProcRes: &ProcRes) { ProcRes: &ProcRes) {
if vec::is_empty(props.error_patterns) { if props.error_patterns.is_empty() {
fatal(~"no error pattern specified in " + testfile.to_str()); fatal(~"no error pattern specified in " + testfile.to_str());
} }

View file

@ -179,7 +179,7 @@ pub mod reader {
} }
pub fn Doc(data: @~[u8]) -> Doc { pub fn Doc(data: @~[u8]) -> Doc {
Doc { data: data, start: 0u, end: vec::len::<u8>(*data) } Doc { data: data, start: 0u, end: data.len() }
} }
pub fn doc_at(data: @~[u8], start: uint) -> TaggedDoc { pub fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {

View file

@ -427,7 +427,7 @@ pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] {
/// Returns the string argument supplied to a matching option or none /// Returns the string argument supplied to a matching option or none
pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> { pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> {
let vals = opt_vals(mm, nm); let vals = opt_vals(mm, nm);
if vec::len::<Optval>(vals) == 0u { return None::<~str>; } if vals.is_empty() { return None::<~str>; }
return match vals[0] { return match vals[0] {
Val(ref s) => Some(copy *s), Val(ref s) => Some(copy *s),
_ => None _ => 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> { pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
let vals = opt_vals(mm, nm); let vals = opt_vals(mm, nm);
if vec::len::<Optval>(vals) == 0u { return None::<~str>; } if vals.is_empty() { return None::<~str>; }
return match vals[0] { Val(ref s) => Some::<~str>(copy *s), return match vals[0] { Val(ref s) => Some::<~str>(copy *s),
_ => Some::<~str>(str::to_owned(def)) } _ => Some::<~str>(str::to_owned(def)) }
} }

View file

@ -195,7 +195,7 @@ pub fn sha1() -> @Sha1 {
* can be assumed that the message digest has been computed. * can be assumed that the message digest has been computed.
*/ */
fn pad_msg(st: &mut Sha1State) { 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 * 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; let tests = fips_180_1_tests + wikipedia_tests;
fn check_vec_eq(v0: ~[u8], v1: ~[u8]) { fn check_vec_eq(v0: ~[u8], v1: ~[u8]) {
assert_eq!(vec::len::<u8>(v0), vec::len::<u8>(v1)); assert_eq!(v0.len(), v1.len());
let len = vec::len::<u8>(v0); let len = v0.len();
let mut i = 0u; let mut i = 0u;
while i < len { while i < len {
let a = v0[i]; let a = v0[i];

View file

@ -15,7 +15,6 @@ use core::prelude::*;
use core::cmp::{Eq, Ord}; use core::cmp::{Eq, Ord};
use core::uint; use core::uint;
use core::util::swap; use core::util::swap;
use core::vec::len;
use core::vec; use core::vec;
type Le<'self, T> = &'self fn(v1: &T, v2: &T) -> bool; 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<T:Copy>(v: &[T], le: Le<T>) -> ~[T] { pub fn merge_sort<T:Copy>(v: &[T], le: Le<T>) -> ~[T] {
type Slice = (uint, uint); type Slice = (uint, uint);
return merge_sort_(v, (0u, len(v)), le); return merge_sort_(v, (0u, v.len()), le);
fn merge_sort_<T:Copy>(v: &[T], slice: Slice, le: Le<T>) fn merge_sort_<T:Copy>(v: &[T], slice: Slice, le: Le<T>)
-> ~[T] { -> ~[T] {
@ -47,10 +46,10 @@ pub fn merge_sort<T:Copy>(v: &[T], le: Le<T>) -> ~[T] {
} }
fn merge<T:Copy>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] { fn merge<T:Copy>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] {
let mut rs = vec::with_capacity(len(a) + len(b)); let mut rs = vec::with_capacity(a.len() + b.len());
let a_len = len(a); let a_len = a.len();
let mut a_ix = 0; let mut a_ix = 0;
let b_len = len(b); let b_len = b.len();
let mut b_ix = 0; let mut b_ix = 0;
while a_ix < a_len && b_ix < b_len { while a_ix < a_len && b_ix < b_len {
if le(&a[a_ix], &b[b_ix]) { if le(&a[a_ix], &b[b_ix]) {
@ -100,8 +99,9 @@ fn qsort<T>(arr: &mut [T], left: uint,
* This is an unstable sort. * This is an unstable sort.
*/ */
pub fn quick_sort<T>(arr: &mut [T], compare_func: Le<T>) { pub fn quick_sort<T>(arr: &mut [T], compare_func: Le<T>) {
if len::<T>(arr) == 0u { return; } let len = arr.len();
qsort::<T>(arr, 0u, len::<T>(arr) - 1u, compare_func); if len == 0u { return; }
qsort::<T>(arr, 0u, len - 1u, compare_func);
} }
fn qsort3<T:Copy + Ord + Eq>(arr: &mut [T], left: int, right: int) { fn qsort3<T:Copy + Ord + Eq>(arr: &mut [T], left: int, right: int) {
@ -138,7 +138,7 @@ fn qsort3<T:Copy + Ord + Eq>(arr: &mut [T], left: int, right: int) {
vec::swap(arr, k as uint, j as uint); vec::swap(arr, k as uint, j as uint);
k += 1; k += 1;
j -= 1; j -= 1;
if k == len::<T>(arr) as int { break; } if k == arr.len() as int { break; }
} }
k = right - 1; k = right - 1;
while k > q { while k > q {
@ -754,7 +754,7 @@ mod test_qsort3 {
use core::vec; use core::vec;
fn check_sort(v1: &mut [int], v2: &mut [int]) { fn check_sort(v1: &mut [int], v2: &mut [int]) {
let len = vec::len::<int>(v1); let len = v1.len();
quick_sort3::<int>(v1); quick_sort3::<int>(v1);
let mut i = 0; let mut i = 0;
while i < len { while i < len {
@ -799,7 +799,7 @@ mod test_qsort {
use core::vec; use core::vec;
fn check_sort(v1: &mut [int], v2: &mut [int]) { fn check_sort(v1: &mut [int], v2: &mut [int]) {
let len = vec::len::<int>(v1); let len = v1.len();
fn leual(a: &int, b: &int) -> bool { *a <= *b } fn leual(a: &int, b: &int) -> bool { *a <= *b }
quick_sort::<int>(v1, leual); quick_sort::<int>(v1, leual);
let mut i = 0u; let mut i = 0u;
@ -864,7 +864,7 @@ mod tests {
use core::vec; use core::vec;
fn check_sort(v1: &[int], v2: &[int]) { fn check_sort(v1: &[int], v2: &[int]) {
let len = vec::len::<int>(v1); let len = v1.len();
pub fn le(a: &int, b: &int) -> bool { *a <= *b } pub fn le(a: &int, b: &int) -> bool { *a <= *b }
let f = le; let f = le;
let v3 = merge_sort::<int>(v1, f); let v3 = merge_sort::<int>(v1, f);
@ -951,7 +951,7 @@ mod test_tim_sort {
} }
fn check_sort(v1: &mut [int], v2: &mut [int]) { fn check_sort(v1: &mut [int], v2: &mut [int]) {
let len = vec::len::<int>(v1); let len = v1.len();
tim_sort::<int>(v1); tim_sort::<int>(v1);
let mut i = 0u; let mut i = 0u;
while i < len { while i < len {

View file

@ -988,7 +988,7 @@ pub unsafe fn accept(server: *libc::c_void, client: *libc::c_void)
pub unsafe fn write<T>(req: *uv_write_t, stream: *T, pub unsafe fn write<T>(req: *uv_write_t, stream: *T,
buf_in: *~[uv_buf_t], cb: *u8) -> libc::c_int { buf_in: *~[uv_buf_t], cb: *u8) -> libc::c_int {
let buf_ptr = vec::raw::to_ptr(*buf_in); 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, return rust_uv_write(req as *libc::c_void,
stream as *libc::c_void, stream as *libc::c_void,
buf_ptr, buf_cnt, cb); buf_ptr, buf_cnt, cb);

View file

@ -624,7 +624,7 @@ pub fn check_roundtrip_convergence(code: @~str, maxIters: uint) {
} }
pub fn check_convergence(files: &[Path]) { 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| { for files.each |file| {
if !file_might_not_converge(file) { if !file_might_not_converge(file) {
let s = @result::get(&io::read_whole_file_str(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() { pub fn main() {
let args = os::args(); let args = os::args();
if vec::len(args) != 2u { if args.len() != 2u {
error!("usage: %s <testdir>", args[0]); error!("usage: %s <testdir>", args[0]);
return; return;
} }

View file

@ -203,8 +203,7 @@ fn is_test_fn(cx: @mut TestCtxt, i: @ast::item) -> bool {
} }
fn is_bench_fn(i: @ast::item) -> bool { fn is_bench_fn(i: @ast::item) -> bool {
let has_bench_attr = let has_bench_attr = !attr::find_attrs_by_name(i.attrs, "bench").is_empty();
vec::len(attr::find_attrs_by_name(i.attrs, "bench")) > 0u;
fn has_test_signature(i: @ast::item) -> bool { fn has_test_signature(i: @ast::item) -> bool {
match i.node { match i.node {
@ -242,7 +241,7 @@ fn is_ignored(cx: @mut TestCtxt, i: @ast::item) -> bool {
} }
fn should_fail(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 { fn add_test_module(cx: &TestCtxt, m: &ast::_mod) -> ast::_mod {

View file

@ -212,7 +212,7 @@ fn get_metadata_section(os: os,
let mut found = None; let mut found = None;
unsafe { unsafe {
let cvbuf: *u8 = cast::transmute(cbuf); 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", debug!("checking %u bytes of metadata-version stamp",
vlen); vlen);
let minsz = uint::min(vlen, csz); let minsz = uint::min(vlen, csz);

View file

@ -786,7 +786,7 @@ pub fn check_fn(cx: @MatchCheckCtxt,
pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool { pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
match cx.tcx.def_map.find(&pat.id) { match cx.tcx.def_map.find(&pat.id) {
Some(&def_variant(enum_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; return true;
} }
} }

View file

@ -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 { 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()
} }

View file

@ -348,7 +348,7 @@ fn is_nullary_variant(cx: Context, ex: @expr) -> bool {
expr_path(_) => { expr_path(_) => {
match cx.tcx.def_map.get_copy(&ex.id) { match cx.tcx.def_map.get_copy(&ex.id) {
def_variant(edid, vdid) => { 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 _ => false
} }

View file

@ -53,14 +53,13 @@ pub fn count_insn(cx: block, category: &str) {
// Pass 1: scan table mapping str -> rightmost pos. // Pass 1: scan table mapping str -> rightmost pos.
let mut mm = HashMap::new(); let mut mm = HashMap::new();
let len = vec::len(*v); let len = v.len();
let mut i = 0u; let mut i = 0u;
while i < len { while i < len {
mm.insert(copy v[i], i); mm.insert(copy v[i], i);
i += 1u; i += 1u;
} }
// Pass 2: concat strings for each elt, skipping // Pass 2: concat strings for each elt, skipping
// forwards over any cycles by advancing to rightmost // forwards over any cycles by advancing to rightmost
// occurrence of each element in path. // occurrence of each element in path.

View file

@ -2373,7 +2373,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
ty_enum(did, ref substs) => { ty_enum(did, ref substs) => {
seen.push(did); seen.push(did);
let vs = enum_variants(cx, 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| { do variant.args.iter().any |aty| {
let sty = subst(cx, substs, *aty); let sty = subst(cx, substs, *aty);
type_requires(cx, seen, r_ty, sty) type_requires(cx, seen, r_ty, sty)

View file

@ -113,9 +113,9 @@ impl ResolveState {
// n.b. This is a hokey mess because the current fold doesn't // n.b. This is a hokey mess because the current fold doesn't
// allow us to pass back errors in any useful way. // 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) ); let rty = indent(|| self.resolve_type(typ) );
assert!(vec::is_empty(self.v_seen)); assert!(self.v_seen.is_empty());
match self.err { match self.err {
None => { None => {
debug!("Resolved to %s + %s (modes=%x)", debug!("Resolved to %s + %s (modes=%x)",

View file

@ -279,7 +279,7 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
version(*binary); version(*binary);
return; return;
} }
let input = match vec::len(matches.free) { let input = match matches.free.len() {
0u => early_error(demitter, ~"no input filename given"), 0u => early_error(demitter, ~"no input filename given"),
1u => { 1u => {
let ifile = /*bad*/copy matches.free[0]; let ifile = /*bad*/copy matches.free[0];

View file

@ -141,7 +141,7 @@ fn should_prune_unconfigured_items() {
let source = ~"#[cfg(shut_up_and_leave_me_alone)]fn a() { }"; let source = ~"#[cfg(shut_up_and_leave_me_alone)]fn a() { }";
do from_str(source) |srv| { do from_str(source) |srv| {
do exec(srv) |ctxt| { do exec(srv) |ctxt| {
assert!(vec::is_empty(ctxt.ast.node.module.items)); assert!(ctxt.ast.node.module.items.is_empty());
} }
} }
} }

View file

@ -295,8 +295,8 @@ mod test {
#[test] #[test]
fn extract_empty_crate() { fn extract_empty_crate() {
let doc = mk_doc(~""); let doc = mk_doc(~"");
assert!(vec::is_empty(doc.cratemod().mods())); assert!(doc.cratemod().mods().is_empty());
assert!(vec::is_empty(doc.cratemod().fns())); assert!(doc.cratemod().fns().is_empty());
} }
#[test] #[test]

View file

@ -343,7 +343,7 @@ fn item_header_lvl(doc: &doc::ItemTag) -> Hlvl {
} }
fn write_index(ctxt: &Ctxt, index: &doc::Index) { fn write_index(ctxt: &Ctxt, index: &doc::Index) {
if vec::is_empty(index.entries) { if index.entries.is_empty() {
return; return;
} }
@ -437,7 +437,7 @@ fn write_variants(
ctxt: &Ctxt, ctxt: &Ctxt,
docs: &[doc::VariantDoc] docs: &[doc::VariantDoc]
) { ) {
if vec::is_empty(docs) { if docs.is_empty() {
return; return;
} }

View file

@ -191,6 +191,6 @@ mod test {
#[test] #[test]
fn should_remove_mods_from_containing_mods() { fn should_remove_mods_from_containing_mods() {
let doc = mk_doc(~"mod a { }"); let doc = mk_doc(~"mod a { }");
assert!(vec::is_empty(doc.cratemod().mods())); assert!(doc.cratemod().mods().is_empty());
} }
} }

View file

@ -80,6 +80,6 @@ mod test {
use core::vec; use core::vec;
let doc = mk_doc(~"#[doc(hidden)] mod a { }"); let doc = mk_doc(~"#[doc(hidden)] mod a { }");
assert!(vec::is_empty(doc.cratemod().mods())) assert!(doc.cratemod().mods().is_empty())
} }
} }

View file

@ -175,7 +175,7 @@ mod test {
#[test] #[test]
fn should_prune_items_without_pub_modifier() { fn should_prune_items_without_pub_modifier() {
let doc = mk_doc(~"mod a { }"); let doc = mk_doc(~"mod a { }");
assert!(vec::is_empty(doc.cratemod().mods())); assert!(doc.cratemod().mods().is_empty());
} }
#[test] #[test]

View file

@ -217,7 +217,7 @@ mod test {
Body\"]\ Body\"]\
mod a { mod a {
}"); }");
assert!(vec::is_empty(doc.cratemod().mods()[0].item.sections)); assert!(doc.cratemod().mods()[0].item.sections.is_empty());
} }
#[test] #[test]

View file

@ -20,6 +20,7 @@ use option::{None, Option, Some};
use old_iter::BaseIter; use old_iter::BaseIter;
use vec; use vec;
use vec::OwnedVector; use vec::OwnedVector;
use container::Container;
/// The result type /// The result type
#[deriving(Clone, Eq)] #[deriving(Clone, Eq)]
@ -301,7 +302,7 @@ impl<T, E: Copy> Result<T, E> {
pub fn map_vec<T,U:Copy,V:Copy>( pub fn map_vec<T,U:Copy,V:Copy>(
ts: &[T], op: &fn(&T) -> Result<V,U>) -> Result<~[V],U> { ts: &[T], op: &fn(&T) -> Result<V,U>) -> 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| { for ts.each |t| {
match op(t) { match op(t) {
Ok(v) => vs.push(v), Ok(v) => vs.push(v),
@ -339,7 +340,7 @@ pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
op: &fn(&S,&T) -> Result<V,U>) -> Result<~[V],U> { op: &fn(&S,&T) -> Result<V,U>) -> Result<~[V],U> {
assert!(vec::same_length(ss, ts)); assert!(vec::same_length(ss, ts));
let n = vec::len(ts); let n = ts.len();
let mut vs = vec::with_capacity(n); let mut vs = vec::with_capacity(n);
let mut i = 0u; let mut i = 0u;
while i < n { while i < n {
@ -362,7 +363,7 @@ pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
op: &fn(&S,&T) -> Result<(),U>) -> Result<(),U> { op: &fn(&S,&T) -> Result<(),U>) -> Result<(),U> {
assert!(vec::same_length(ss, ts)); assert!(vec::same_length(ss, ts));
let n = vec::len(ts); let n = ts.len();
let mut i = 0u; let mut i = 0u;
while i < n { while i < n {
match op(&ss[i],&ts[i]) { match op(&ss[i],&ts[i]) {

View file

@ -1752,7 +1752,7 @@ Section: Misc
/// Determines if a vector of bytes contains valid UTF-8 /// Determines if a vector of bytes contains valid UTF-8
pub fn is_utf8(v: &const [u8]) -> bool { pub fn is_utf8(v: &const [u8]) -> bool {
let mut i = 0u; let mut i = 0u;
let total = vec::len::<u8>(v); let total = v.len();
while i < total { while i < total {
let mut chsize = utf8_char_width(v[i]); let mut chsize = utf8_char_width(v[i]);
if chsize == 0u { return false; } if chsize == 0u { return false; }
@ -3693,7 +3693,7 @@ mod tests {
let s2: ~str = from_bytes(v); let s2: ~str = from_bytes(v);
let mut i: uint = 0u; let mut i: uint = 0u;
let n1: uint = len(s1); let n1: uint = len(s1);
let n2: uint = vec::len::<u8>(v); let n2: uint = v.len();
assert_eq!(n1, n2); assert_eq!(n1, n2);
while i < n1 { while i < n1 {
let a: u8 = s1[i]; let a: u8 = s1[i];

View file

@ -56,11 +56,6 @@ pub mod rustrt {
} }
} }
/// Returns true if a vector contains no elements
pub fn is_empty<T>(v: &const [T]) -> bool {
as_const_buf(v, |_p, len| len == 0u)
}
/// Returns true if two vectors have the same length /// Returns true if two vectors have the same length
pub fn same_length<T, U>(xs: &const [T], ys: &const [U]) -> bool { pub fn same_length<T, U>(xs: &const [T], ys: &const [U]) -> bool {
xs.len() == ys.len() xs.len() == ys.len()
@ -123,12 +118,6 @@ pub fn capacity<T>(v: &const ~[T]) -> uint {
} }
} }
/// Returns the length of a vector
#[inline(always)]
pub fn len<T>(v: &const [T]) -> uint {
as_const_buf(v, |_p, len| len)
}
// A botch to tide us over until core and std are fully demuted. // A botch to tide us over until core and std are fully demuted.
#[allow(missing_doc)] #[allow(missing_doc)]
pub fn uniq_len<T>(v: &const ~[T]) -> uint { pub fn uniq_len<T>(v: &const ~[T]) -> uint {
@ -291,7 +280,7 @@ pub fn last_opt<'r,T>(v: &'r [T]) -> Option<&'r T> {
#[inline(always)] #[inline(always)]
pub fn slice<'r,T>(v: &'r [T], start: uint, end: uint) -> &'r [T] { pub fn slice<'r,T>(v: &'r [T], start: uint, end: uint) -> &'r [T] {
assert!(start <= end); assert!(start <= end);
assert!(end <= len(v)); assert!(end <= v.len());
do as_imm_buf(v) |p, _len| { do as_imm_buf(v) |p, _len| {
unsafe { unsafe {
transmute((ptr::offset(p, start), 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) pub fn const_slice<'r,T>(v: &'r const [T], start: uint, end: uint)
-> &'r const [T] { -> &'r const [T] {
assert!(start <= end); assert!(start <= end);
assert!(end <= len(v)); assert!(end <= v.len());
do as_const_buf(v) |p, _len| { do as_const_buf(v) |p, _len| {
unsafe { unsafe {
transmute((ptr::const_offset(p, start), 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`. /// Split the vector `v` by applying each element against the predicate `f`.
pub fn split<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { pub fn split<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v); let ln = v.len();
if (ln == 0u) { return ~[] } if (ln == 0u) { return ~[] }
let mut start = 0u; let mut start = 0u;
@ -355,7 +344,7 @@ pub fn split<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
* to `n` times. * to `n` times.
*/ */
pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v); let ln = v.len();
if (ln == 0u) { return ~[] } if (ln == 0u) { return ~[] }
let mut start = 0u; let mut start = 0u;
@ -381,7 +370,7 @@ pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
* `f`. * `f`.
*/ */
pub fn rsplit<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { pub fn rsplit<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v); let ln = v.len();
if (ln == 0) { return ~[] } if (ln == 0) { return ~[] }
let mut end = ln; let mut end = ln;
@ -405,7 +394,7 @@ pub fn rsplit<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
* `f` up to `n times. * `f` up to `n times.
*/ */
pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v); let ln = v.len();
if (ln == 0u) { return ~[] } if (ln == 0u) { return ~[] }
let mut end = ln; let mut end = ln;
@ -861,7 +850,7 @@ pub fn grow_set<T:Copy>(v: &mut ~[T], index: uint, initval: &T, val: T) {
/// Apply a function to each element of a vector and return the results /// Apply a function to each element of a vector and return the results
pub fn map<T, U>(v: &[T], f: &fn(t: &T) -> U) -> ~[U] { pub fn map<T, U>(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| { for each(v) |elem| {
result.push(f(elem)); result.push(f(elem));
} }
@ -908,8 +897,8 @@ pub fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
*/ */
pub fn map_zip<T:Copy,U:Copy,V>(v0: &[T], v1: &[U], pub fn map_zip<T:Copy,U:Copy,V>(v0: &[T], v1: &[U],
f: &fn(t: &T, v: &U) -> V) -> ~[V] { f: &fn(t: &T, v: &U) -> V) -> ~[V] {
let v0_len = len(v0); let v0_len = v0.len();
if v0_len != len(v1) { fail!(); } if v0_len != v1.len() { fail!(); }
let mut u: ~[V] = ~[]; let mut u: ~[V] = ~[];
let mut i = 0u; let mut i = 0u;
while i < v0_len { while i < v0_len {
@ -1080,7 +1069,7 @@ pub fn contains<T:Eq>(v: &[T], x: &T) -> bool {
* is returned. If `f` matches no elements then none is returned. * is returned. If `f` matches no elements then none is returned.
*/ */
pub fn find<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> { pub fn find<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
find_between(v, 0u, len(v), f) find_between(v, 0u, v.len(), f)
} }
/** /**
@ -1103,7 +1092,7 @@ pub fn find_between<T:Copy>(v: &[T], start: uint, end: uint,
* matches no elements then none is returned. * matches no elements then none is returned.
*/ */
pub fn rfind<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> { pub fn rfind<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
rfind_between(v, 0u, len(v), f) rfind_between(v, 0u, v.len(), f)
} }
/** /**
@ -1134,7 +1123,7 @@ pub fn position_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
* then none is returned. * then none is returned.
*/ */
pub fn position<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> { pub fn position<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
position_between(v, 0u, len(v), f) position_between(v, 0u, v.len(), f)
} }
/** /**
@ -1150,7 +1139,7 @@ pub fn position_between<T>(v: &[T],
f: &fn(t: &T) -> bool) f: &fn(t: &T) -> bool)
-> Option<uint> { -> Option<uint> {
assert!(start <= end); assert!(start <= end);
assert!(end <= len(v)); assert!(end <= v.len());
let mut i = start; let mut i = start;
while i < end { if f(&v[i]) { return Some::<uint>(i); } i += 1u; } while i < end { if f(&v[i]) { return Some::<uint>(i); } i += 1u; }
None None
@ -1169,7 +1158,7 @@ pub fn rposition_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
* matches no elements then none is returned. * matches no elements then none is returned.
*/ */
pub fn rposition<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> { pub fn rposition<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
rposition_between(v, 0u, len(v), f) rposition_between(v, 0u, v.len(), f)
} }
/** /**
@ -1183,7 +1172,7 @@ pub fn rposition<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
pub fn rposition_between<T>(v: &[T], start: uint, end: uint, pub fn rposition_between<T>(v: &[T], start: uint, end: uint,
f: &fn(t: &T) -> bool) -> Option<uint> { f: &fn(t: &T) -> bool) -> Option<uint> {
assert!(start <= end); assert!(start <= end);
assert!(end <= len(v)); assert!(end <= v.len());
let mut i = end; let mut i = end;
while i > start { while i > start {
if f(&v[i - 1u]) { return Some::<uint>(i - 1u); } if f(&v[i - 1u]) { return Some::<uint>(i - 1u); }
@ -1273,9 +1262,9 @@ pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
pub fn zip_slice<T:Copy,U:Copy>(v: &const [T], u: &const [U]) pub fn zip_slice<T:Copy,U:Copy>(v: &const [T], u: &const [U])
-> ~[(T, U)] { -> ~[(T, U)] {
let mut zipped = ~[]; let mut zipped = ~[];
let sz = len(v); let sz = v.len();
let mut i = 0u; let mut i = 0u;
assert_eq!(sz, len(u)); assert_eq!(sz, u.len());
while i < sz { while i < sz {
zipped.push((v[i], u[i])); zipped.push((v[i], u[i]));
i += 1u; i += 1u;
@ -1290,8 +1279,8 @@ pub fn zip_slice<T:Copy,U:Copy>(v: &const [T], u: &const [U])
* i-th elements from each of the input vectors. * i-th elements from each of the input vectors.
*/ */
pub fn zip<T, U>(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] { pub fn zip<T, U>(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] {
let mut i = len(v); let mut i = v.len();
assert_eq!(i, len(u)); assert_eq!(i, u.len());
let mut w = with_capacity(i); let mut w = with_capacity(i);
while i > 0 { while i > 0 {
w.push((v.pop(),u.pop())); w.push((v.pop(),u.pop()));
@ -1324,7 +1313,7 @@ pub fn swap<T>(v: &mut [T], a: uint, b: uint) {
/// Reverse the order of elements in a vector, in place /// Reverse the order of elements in a vector, in place
pub fn reverse<T>(v: &mut [T]) { pub fn reverse<T>(v: &mut [T]) {
let mut i: uint = 0; let mut i: uint = 0;
let ln = len::<T>(v); let ln = v.len();
while i < ln / 2 { while i < ln / 2 {
swap(v, i, ln - i - 1); swap(v, i, ln - i - 1);
i += 1; i += 1;
@ -1372,7 +1361,7 @@ pub fn reverse_part<T>(v: &mut [T], start: uint, end : uint) {
/// Returns a vector with the order of elements reversed /// Returns a vector with the order of elements reversed
pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] { pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
let mut rs: ~[T] = ~[]; let mut rs: ~[T] = ~[];
let mut i = len::<T>(v); let mut i = v.len();
if i == 0 { return (rs); } else { i -= 1; } if i == 0 { return (rs); } else { i -= 1; }
while i != 0 { rs.push(v[i]); i -= 1; } while i != 0 { rs.push(v[i]); i -= 1; }
rs.push(v[0]); 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 * of elements in `v` (so if `v` is sorted then the permutations are
* lexicographically sorted). * 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. * repeated elements, then some permutations are repeated.
* *
* See [Algorithms to generate * See [Algorithms to generate
@ -1779,11 +1768,16 @@ pub mod traits {
impl<'self,T> Container for &'self const [T] { impl<'self,T> Container for &'self const [T] {
/// Returns true if a vector contains no elements /// Returns true if a vector contains no elements
#[inline] #[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 /// Returns the length of a vector
#[inline] #[inline]
fn len(&const self) -> uint { len(*self) } fn len(&const self) -> uint {
as_const_buf(*self, |_p, len| len)
}
} }
#[allow(missing_doc)] #[allow(missing_doc)]
@ -2250,7 +2244,7 @@ pub mod raw {
use ptr; use ptr;
use sys; use sys;
use unstable::intrinsics; 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; use util;
/// The internal representation of a (boxed) vector /// The internal representation of a (boxed) vector
@ -2872,8 +2866,9 @@ mod tests {
#[test] #[test]
fn test_is_empty() { fn test_is_empty() {
assert!(is_empty::<int>([])); let xs: [int, ..0] = [];
assert!(!is_empty([0])); assert!(xs.is_empty());
assert!(![0].is_empty());
} }
#[test] #[test]

View file

@ -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 { 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 //FIXME /* FIXME (#2543) */ copy *i
copy *itr.get(i.name) copy *itr.get(i.name)
} else { } else {

View file

@ -2768,7 +2768,7 @@ impl Parser {
attributes_box.push_all(self.parse_outer_attributes()); attributes_box.push_all(self.parse_outer_attributes());
match *self.token { match *self.token {
token::SEMI => { token::SEMI => {
if !vec::is_empty(attributes_box) { if !attributes_box.is_empty() {
self.span_err(*self.last_span, "expected item after attributes"); self.span_err(*self.last_span, "expected item after attributes");
attributes_box = ~[]; 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"); self.span_err(*self.last_span, "expected item after attributes");
} }

View file

@ -2041,7 +2041,7 @@ pub fn lit_to_str(l: @ast::lit) -> ~str {
pub fn next_lit(s: @ps, pos: BytePos) -> Option<comments::lit> { pub fn next_lit(s: @ps, pos: BytePos) -> Option<comments::lit> {
match s.literals { match s.literals {
Some(ref lits) => { 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]; let ltrl = /*bad*/ copy (*lits)[s.cur_cmnt_and_lit.cur_lit];
if ltrl.pos > pos { return None; } if ltrl.pos > pos { return None; }
s.cur_cmnt_and_lit.cur_lit += 1u; s.cur_cmnt_and_lit.cur_lit += 1u;
@ -2128,7 +2128,7 @@ pub fn to_str<T: Copy>(t: T, f: @fn(@ps, T), intr: @ident_interner) -> ~str {
pub fn next_comment(s: @ps) -> Option<comments::cmnt> { pub fn next_comment(s: @ps) -> Option<comments::cmnt> {
match s.comments { match s.comments {
Some(ref cmnts) => { 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]); return Some(copy cmnts[s.cur_cmnt_and_lit.cur_cmnt]);
} else { return None::<comments::cmnt>; } } else { return None::<comments::cmnt>; }
} }

View file

@ -40,7 +40,7 @@ fn send(p: &pipe, msg: uint) {
fn recv(p: &pipe) -> uint { fn recv(p: &pipe) -> uint {
unsafe { unsafe {
do p.access_cond |state, cond| { do p.access_cond |state, cond| {
while vec::is_empty(*state) { while state.is_empty() {
cond.wait(); cond.wait();
} }
state.pop() state.pop()

View file

@ -37,7 +37,7 @@ fn send(p: &pipe, msg: uint) {
} }
fn recv(p: &pipe) -> uint { fn recv(p: &pipe) -> uint {
do p.write_cond |state, cond| { do p.write_cond |state, cond| {
while vec::is_empty(*state) { while state.is_empty() {
cond.wait(); cond.wait();
} }
state.pop() state.pop()

View file

@ -64,7 +64,7 @@ fn select_random(r: u32, genelist: ~[AminoAcids]) -> char {
} else { return bisect(v, mid, hi, target); } } else { return bisect(v, mid, hi, target); }
} else { return v[hi].ch; } } else { return v[hi].ch; }
} }
return bisect(copy genelist, 0, vec::len::<AminoAcids>(genelist) - 1, r); return bisect(copy genelist, 0, genelist.len() - 1, r);
} }
fn make_random_fasta(wr: @io::Writer, fn make_random_fasta(wr: @io::Writer,

View file

@ -9,10 +9,12 @@
// except according to those terms. // except according to those terms.
pub fn main() { pub fn main() {
use std::vec::from_fn; use std::util::replace;
debug!(::std::vec::len(from_fn(2, |i| i))); let mut x = 5;
replace(&mut x, 6);
{ {
use std::vec::*; use std::util::*;
debug!(len(~[2])); let mut y = 6;
swap(&mut x, &mut y);
} }
} }

View file

@ -20,7 +20,7 @@ pub fn main() {
grow(&mut v); grow(&mut v);
grow(&mut v); grow(&mut v);
grow(&mut v); grow(&mut v);
let len = vec::len::<int>(v); let len = v.len();
debug!(len); debug!(len);
assert_eq!(len, 3 as uint); assert_eq!(len, 3 as uint);
} }

View file

@ -47,7 +47,7 @@ trait vec_utils<T> {
} }
impl<T> vec_utils<T> for ~[T] { impl<T> vec_utils<T> 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 iter_(&self, f: &fn(&T)) { for self.each |x| { f(x); } }
fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] { fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] {
let mut r = ~[]; let mut r = ~[];

View file

@ -20,7 +20,7 @@ pub fn main() {
assert!(str::len(s) == 10u); assert!(str::len(s) == 10u);
assert!(str::char_len(s) == 4u); 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::from_chars(str::to_chars(s)) == s);
assert!(str::char_at(s, 0u) == 'e'); assert!(str::char_at(s, 0u) == 'e');
assert!(str::char_at(s, 1u) == 'é'); assert!(str::char_at(s, 1u) == 'é');