auto merge of #7023 : thestinger/rust/vec, r=brson
This commit is contained in:
commit
88c318d28c
@ -2046,7 +2046,7 @@ trait Seq<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)) {
|
||||
for vec::each(*self) |elt| { b(elt); }
|
||||
}
|
||||
|
@ -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)),
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ pub mod reader {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -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::<Optval>(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::<Optval>(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)) }
|
||||
}
|
||||
|
@ -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::<u8>(v0), vec::len::<u8>(v1));
|
||||
let len = vec::len::<u8>(v0);
|
||||
assert_eq!(v0.len(), v1.len());
|
||||
let len = v0.len();
|
||||
let mut i = 0u;
|
||||
while i < len {
|
||||
let a = v0[i];
|
||||
|
@ -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<T:Copy>(v: &[T], le: Le<T>) -> ~[T] {
|
||||
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>)
|
||||
-> ~[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] {
|
||||
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<T>(arr: &mut [T], left: uint,
|
||||
* This is an unstable sort.
|
||||
*/
|
||||
pub fn quick_sort<T>(arr: &mut [T], compare_func: Le<T>) {
|
||||
if len::<T>(arr) == 0u { return; }
|
||||
qsort::<T>(arr, 0u, len::<T>(arr) - 1u, compare_func);
|
||||
let len = arr.len();
|
||||
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) {
|
||||
@ -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);
|
||||
k += 1;
|
||||
j -= 1;
|
||||
if k == len::<T>(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::<int>(v1);
|
||||
let len = v1.len();
|
||||
quick_sort3::<int>(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::<int>(v1);
|
||||
let len = v1.len();
|
||||
fn leual(a: &int, b: &int) -> bool { *a <= *b }
|
||||
quick_sort::<int>(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::<int>(v1);
|
||||
let len = v1.len();
|
||||
pub fn le(a: &int, b: &int) -> bool { *a <= *b }
|
||||
let f = le;
|
||||
let v3 = merge_sort::<int>(v1, f);
|
||||
@ -951,7 +951,7 @@ mod test_tim_sort {
|
||||
}
|
||||
|
||||
fn check_sort(v1: &mut [int], v2: &mut [int]) {
|
||||
let len = vec::len::<int>(v1);
|
||||
let len = v1.len();
|
||||
tim_sort::<int>(v1);
|
||||
let mut i = 0u;
|
||||
while i < len {
|
||||
|
@ -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,
|
||||
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);
|
||||
|
@ -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 <testdir>", args[0]);
|
||||
return;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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)",
|
||||
|
@ -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];
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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<T, E: Copy> Result<T, E> {
|
||||
pub fn map_vec<T,U:Copy,V:Copy>(
|
||||
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| {
|
||||
match op(t) {
|
||||
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> {
|
||||
|
||||
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<S,T,U:Copy>(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]) {
|
||||
|
@ -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::<u8>(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::<u8>(v);
|
||||
let n2: uint = v.len();
|
||||
assert_eq!(n1, n2);
|
||||
while i < n1 {
|
||||
let a: u8 = s1[i];
|
||||
|
@ -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
|
||||
pub fn same_length<T, U>(xs: &const [T], ys: &const [U]) -> bool {
|
||||
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.
|
||||
#[allow(missing_doc)]
|
||||
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)]
|
||||
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<T:Copy>(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<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
|
||||
* to `n` times.
|
||||
*/
|
||||
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 ~[] }
|
||||
|
||||
let mut start = 0u;
|
||||
@ -381,7 +370,7 @@ pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
|
||||
* `f`.
|
||||
*/
|
||||
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 ~[] }
|
||||
|
||||
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.
|
||||
*/
|
||||
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 ~[] }
|
||||
|
||||
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
|
||||
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| {
|
||||
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],
|
||||
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<T:Eq>(v: &[T], x: &T) -> bool {
|
||||
* 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> {
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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)
|
||||
-> Option<uint> {
|
||||
assert!(start <= end);
|
||||
assert!(end <= len(v));
|
||||
assert!(end <= v.len());
|
||||
let mut i = start;
|
||||
while i < end { if f(&v[i]) { return Some::<uint>(i); } i += 1u; }
|
||||
None
|
||||
@ -1169,7 +1158,7 @@ pub fn rposition_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
|
||||
* matches no elements then none is returned.
|
||||
*/
|
||||
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,
|
||||
f: &fn(t: &T) -> bool) -> Option<uint> {
|
||||
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::<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])
|
||||
-> ~[(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<T:Copy,U:Copy>(v: &const [T], u: &const [U])
|
||||
* i-th elements from each of the input vectors.
|
||||
*/
|
||||
pub fn zip<T, U>(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<T>(v: &mut [T], a: uint, b: uint) {
|
||||
/// Reverse the order of elements in a vector, in place
|
||||
pub fn reverse<T>(v: &mut [T]) {
|
||||
let mut i: uint = 0;
|
||||
let ln = len::<T>(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<T>(v: &mut [T], start: uint, end : uint) {
|
||||
/// Returns a vector with the order of elements reversed
|
||||
pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
|
||||
let mut rs: ~[T] = ~[];
|
||||
let mut i = len::<T>(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::<int>([]));
|
||||
assert!(!is_empty([0]));
|
||||
let xs: [int, ..0] = [];
|
||||
assert!(xs.is_empty());
|
||||
assert!(![0].is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -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 {
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -2041,7 +2041,7 @@ pub fn lit_to_str(l: @ast::lit) -> ~str {
|
||||
pub fn next_lit(s: @ps, pos: BytePos) -> Option<comments::lit> {
|
||||
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: Copy>(t: T, f: @fn(@ps, T), intr: @ident_interner) -> ~str {
|
||||
pub fn next_comment(s: @ps) -> Option<comments::cmnt> {
|
||||
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::<comments::cmnt>; }
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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::<AminoAcids>(genelist) - 1, r);
|
||||
return bisect(copy genelist, 0, genelist.len() - 1, r);
|
||||
}
|
||||
|
||||
fn make_random_fasta(wr: @io::Writer,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ pub fn main() {
|
||||
grow(&mut v);
|
||||
grow(&mut v);
|
||||
grow(&mut v);
|
||||
let len = vec::len::<int>(v);
|
||||
let len = v.len();
|
||||
debug!(len);
|
||||
assert_eq!(len, 3 as uint);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ trait vec_utils<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 map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] {
|
||||
let mut r = ~[];
|
||||
|
@ -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) == 'é');
|
||||
|
Loading…
Reference in New Issue
Block a user