Skip to content

Commit 883c966

Browse files
committed
vec: replace position with iter().position_
1 parent 49c7452 commit 883c966

File tree

8 files changed

+13
-54
lines changed

8 files changed

+13
-54
lines changed

src/libextra/getopts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn name_str(nm: &Name) -> ~str {
177177
}
178178

179179
fn find_opt(opts: &[Opt], nm: Name) -> Option<uint> {
180-
vec::position(opts, |opt| opt.name == nm)
180+
opts.iter().position_(|opt| opt.name == nm)
181181
}
182182

183183
/**

src/libextra/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ impl serialize::Decoder for Decoder {
950950
}
951951
ref json => fail!("invalid variant: %?", *json),
952952
};
953-
let idx = match vec::position(names, |n| str::eq_slice(*n, name)) {
953+
let idx = match names.iter().position_(|n| str::eq_slice(*n, name)) {
954954
Some(idx) => idx,
955955
None => fail!("Unknown variant name: %?", name),
956956
};

src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
468468
pub fn revoke_clean(cx: block, val: ValueRef) {
469469
do in_scope_cx(cx) |scope_info| {
470470
let scope_info = &mut *scope_info; // FIXME(#5074) workaround borrowck
471-
let cleanup_pos = vec::position(
472-
scope_info.cleanups,
471+
let cleanup_pos = scope_info.cleanups.iter().position_(
473472
|cu| match *cu {
474473
clean_temp(v, _, _) if v == val => true,
475474
_ => false

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,8 +1152,7 @@ fn trans_rec_or_struct(bcx: block,
11521152
let mut need_base = vec::from_elem(field_tys.len(), true);
11531153

11541154
let numbered_fields = do fields.map |field| {
1155-
let opt_pos = vec::position(field_tys, |field_ty|
1156-
field_ty.ident == field.node.ident);
1155+
let opt_pos = field_tys.iter().position_(|field_ty| field_ty.ident == field.node.ident);
11571156
match opt_pos {
11581157
Some(i) => {
11591158
need_base[i] = false;

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3372,7 +3372,7 @@ pub fn field_idx_strict(tcx: ty::ctxt, id: ast::ident, fields: &[field])
33723372
}
33733373

33743374
pub fn method_idx(id: ast::ident, meths: &[@Method]) -> Option<uint> {
3375-
vec::position(meths, |m| m.ident == id)
3375+
meths.iter().position_(|m| m.ident == id)
33763376
}
33773377

33783378
/// Returns a vector containing the indices of all type parameters that appear

src/librustc/middle/typeck/check/method.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'self> LookupContext<'self> {
420420

421421
let tcx = self.tcx();
422422
let ms = ty::trait_methods(tcx, did);
423-
let index = match vec::position(*ms, |m| m.ident == self.m_name) {
423+
let index = match ms.iter().position_(|m| m.ident == self.m_name) {
424424
Some(i) => i,
425425
None => { return; } // no method with the right name
426426
};
@@ -474,7 +474,7 @@ impl<'self> LookupContext<'self> {
474474
// First, try self methods
475475
let mut method_info: Option<MethodInfo> = None;
476476
let methods = ty::trait_methods(tcx, did);
477-
match vec::position(*methods, |m| m.ident == self.m_name) {
477+
match methods.iter().position_(|m| m.ident == self.m_name) {
478478
Some(i) => {
479479
method_info = Some(MethodInfo {
480480
method_ty: methods[i],
@@ -489,8 +489,7 @@ impl<'self> LookupContext<'self> {
489489
for ty::trait_supertraits(tcx, did).each() |trait_ref| {
490490
let supertrait_methods =
491491
ty::trait_methods(tcx, trait_ref.def_id);
492-
match vec::position(*supertrait_methods,
493-
|m| m.ident == self.m_name) {
492+
match supertrait_methods.iter().position_(|m| m.ident == self.m_name) {
494493
Some(i) => {
495494
method_info = Some(MethodInfo {
496495
method_ty: supertrait_methods[i],

src/libstd/iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use iter::{FromIter, Times};
2222
use num::{Zero, One};
2323
use option::{Option, Some, None};
2424
use ops::{Add, Mul};
25-
use cmp::{Ord, Eq};
25+
use cmp::Ord;
2626
use clone::Clone;
2727

2828
/// An interface for dealing with "external iterators". These types of iterators

src/libstd/vec.rs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
1919
use clone::Clone;
2020
use old_iter::BaseIter;
2121
use old_iter;
22-
use iterator::{Iterator};
22+
use iterator::{Iterator, IteratorUtil};
2323
use iter::FromIter;
2424
use kinds::Copy;
2525
use libc;
@@ -1107,18 +1107,7 @@ pub fn rfind_between<T:Copy>(v: &[T],
11071107

11081108
/// Find the first index containing a matching value
11091109
pub fn position_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
1110-
position(v, |y| *x == *y)
1111-
}
1112-
1113-
/**
1114-
* Find the first index matching some predicate
1115-
*
1116-
* Apply function `f` to each element of `v`. When function `f` returns true
1117-
* then an option containing the index is returned. If `f` matches no elements
1118-
* then none is returned.
1119-
*/
1120-
pub fn position<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
1121-
position_between(v, 0u, v.len(), f)
1110+
v.iter().position_(|y| *x == *y)
11221111
}
11231112

11241113
/**
@@ -3146,18 +3135,6 @@ mod tests {
31463135
assert!(position_elem(v1, &4).is_none());
31473136
}
31483137

3149-
#[test]
3150-
fn test_position() {
3151-
fn less_than_three(i: &int) -> bool { *i < 3 }
3152-
fn is_eighteen(i: &int) -> bool { *i == 18 }
3153-
3154-
assert!(position([], less_than_three).is_none());
3155-
3156-
let v1 = ~[5, 4, 3, 2, 1];
3157-
assert_eq!(position(v1, less_than_three), Some(3u));
3158-
assert!(position(v1, is_eighteen).is_none());
3159-
}
3160-
31613138
#[test]
31623139
fn test_position_between() {
31633140
assert!(position_between([], 0u, 0u, f).is_none());
@@ -3234,8 +3211,8 @@ mod tests {
32343211
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
32353212
let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
32363213

3237-
assert_eq!(position(v, f), Some(1u));
3238-
assert!(position(v, g).is_none());
3214+
assert_eq!(rposition(v, f), Some(3u));
3215+
assert!(rposition(v, g).is_none());
32393216
}
32403217

32413218
#[test]
@@ -3877,21 +3854,6 @@ mod tests {
38773854
};
38783855
}
38793856

3880-
#[test]
3881-
#[ignore(windows)]
3882-
#[should_fail]
3883-
fn test_position_fail() {
3884-
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
3885-
let mut i = 0;
3886-
do position(v) |_elt| {
3887-
if i == 2 {
3888-
fail!()
3889-
}
3890-
i += 0;
3891-
false
3892-
};
3893-
}
3894-
38953857
#[test]
38963858
#[ignore(windows)]
38973859
#[should_fail]

0 commit comments

Comments
 (0)