Skip to content

Commit 41176a0

Browse files
committed
---
yaml --- r: 7886 b: refs/heads/snap-stage3 c: 259636a h: refs/heads/master v: v3
1 parent f5a52ca commit 41176a0

File tree

8 files changed

+28
-25
lines changed

8 files changed

+28
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a831e7ce13aa19acf0f65e508097351f8dabca84
4+
refs/heads/snap-stage3: 259636a112804b94530c409a468b97d4366bb0d3
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,8 @@ for the parameter list, as in `{|| ...}`.
929929
Partial application is done using the `bind` keyword in Rust.
930930

931931
~~~~
932-
let daynum = bind vec::position(_, ["mo", "tu", "we", "do",
933-
"fr", "sa", "su"]);
932+
let daynum = bind vec::position_elt(["mo", "tu", "we", "do",
933+
"fr", "sa", "su"], _);
934934
~~~~
935935

936936
Binding a function produces a boxed closure (`fn@` type) in which some

branches/snap-stage3/src/comp/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ fn filter_invalid(src: list<@invalid>, bs: [binding]) -> list<@invalid> {
679679
while cur != list::nil {
680680
alt cur {
681681
list::cons(head, tail) {
682-
let p = vec::position_pred(bs, {|b| b.node_id == head.node_id});
682+
let p = vec::position(bs, {|b| b.node_id == head.node_id});
683683
if !is_none(p) { out = list::cons(head, @out); }
684684
cur = *tail;
685685
}

branches/snap-stage3/src/comp/middle/shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
430430
}
431431
ty::ty_param(n, _) {
432432
// Find the type parameter in the parameter list.
433-
alt vec::position(n, ty_param_map) {
433+
alt vec::position_elt(ty_param_map, n) {
434434
some(i) { s += [shape_var, i as u8]; }
435435
none { fail "ty param not found in ty_param_map"; }
436436
}

branches/snap-stage3/src/comp/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3375,7 +3375,7 @@ fn trans_rec(bcx: @block_ctxt, fields: [ast::field],
33753375
let ty_fields = alt ty::struct(bcx_tcx(bcx), t) { ty::ty_rec(f) { f } };
33763376
let temp_cleanups = [];
33773377
for fld in fields {
3378-
let ix = option::get(vec::position_pred(ty_fields, {|ft|
3378+
let ix = option::get(vec::position(ty_fields, {|ft|
33793379
str::eq(fld.node.ident, ft.ident)
33803380
}));
33813381
let dst = GEP_tup_like_1(bcx, t, addr, [0, ix as int]);

branches/snap-stage3/src/comp/middle/typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
15131513
ty::ty_iface(i, tps) { (i, tps) }
15141514
};
15151515
let ifce_methods = ty::iface_methods(tcx, iid);
1516-
alt vec::position_pred(*ifce_methods, {|m| m.ident == name}) {
1516+
alt vec::position(*ifce_methods, {|m| m.ident == name}) {
15171517
some(pos) {
15181518
let m = ifce_methods[pos];
15191519
ret some({method_ty: ty::mk_fn(tcx, m.fty),

branches/snap-stage3/src/libcore/vec.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ fn find<T: copy>(v: [T], f: fn(T) -> bool) -> option::t<T> {
614614
}
615615

616616
/*
617-
Function: position
617+
Function: position_elt
618618
619619
Find the first index containing a matching value
620620
@@ -623,18 +623,16 @@ Returns:
623623
option::some(uint) - The first index containing a matching value
624624
option::none - No elements matched
625625
*/
626-
fn position<T>(x: T, v: [T]) -> option::t<uint> {
627-
let i: uint = 0u;
628-
while i < len(v) { if x == v[i] { ret some::<uint>(i); } i += 1u; }
629-
ret none;
626+
fn position_elt<T>(v: [T], x: T) -> option::t<uint> {
627+
position(v) { |y| x == y }
630628
}
631629

632630
/*
633-
Function: position_pred
631+
Function: position
634632
635633
Find the first index for which the value matches some predicate
636634
*/
637-
fn position_pred<T>(v: [T], f: fn(T) -> bool) -> option::t<uint> {
635+
fn position<T>(v: [T], f: fn(T) -> bool) -> option::t<uint> {
638636
let i: uint = 0u;
639637
while i < len(v) { if f(v[i]) { ret some::<uint>(i); } i += 1u; }
640638
ret none;
@@ -1453,21 +1451,26 @@ mod tests {
14531451
}
14541452

14551453
#[test]
1456-
fn test_position() {
1457-
let v1: [int] = [1, 2, 3, 3, 2, 5];
1458-
assert (position(1, v1) == option::some::<uint>(0u));
1459-
assert (position(2, v1) == option::some::<uint>(1u));
1460-
assert (position(5, v1) == option::some::<uint>(5u));
1461-
assert (position(4, v1) == option::none::<uint>);
1454+
fn test_position_elt() {
1455+
assert position_elt([], 1) == none;
1456+
1457+
let v1 = [1, 2, 3, 3, 2, 5];
1458+
assert position_elt(v1, 1) == some(0u);
1459+
assert position_elt(v1, 2) == some(1u);
1460+
assert position_elt(v1, 5) == some(5u);
1461+
assert position_elt(v1, 4) == none;
14621462
}
14631463

14641464
#[test]
1465-
fn test_position_pred() {
1465+
fn test_position() {
14661466
fn less_than_three(&&i: int) -> bool { ret i < 3; }
14671467
fn is_eighteen(&&i: int) -> bool { ret i == 18; }
1468-
let v1: [int] = [5, 4, 3, 2, 1];
1469-
assert position_pred(v1, less_than_three) == option::some::<uint>(3u);
1470-
assert position_pred(v1, is_eighteen) == option::none::<uint>;
1468+
1469+
assert position([], less_than_three) == none;
1470+
1471+
let v1 = [5, 4, 3, 2, 1];
1472+
assert position(v1, less_than_three) == some(3u);
1473+
assert position(v1, is_eighteen) == none;
14711474
}
14721475

14731476
#[test]

branches/snap-stage3/src/libstd/getopts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn name_str(nm: name) -> str {
149149
}
150150

151151
fn find_opt(opts: [opt], nm: name) -> option::t<uint> {
152-
vec::position_pred(opts, { |opt| opt.name == nm })
152+
vec::position(opts, { |opt| opt.name == nm })
153153
}
154154

155155
/*

0 commit comments

Comments
 (0)