Skip to content

Commit f19742d

Browse files
committed
---
yaml --- r: 138735 b: refs/heads/try2 c: d60747a h: refs/heads/master i: 138733: 7bf6424 138731: 4a84979 138727: d1dab3f 138719: 382c462 v: v3
1 parent 2d3dd37 commit f19742d

File tree

4 files changed

+55
-27
lines changed

4 files changed

+55
-27
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 5ae06ae9dea2f1dac157193b702f640e2216a5a9
8+
refs/heads/try2: d60747a24839c50165b0e2ea35592a7cb008f69b
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/vec.rs

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,11 @@ pub pure fn tail<T>(v: &r/[T]) -> &r/[T] { slice(v, 1, v.len()) }
229229
pub pure fn tailn<T>(v: &r/[T], n: uint) -> &r/[T] { slice(v, n, v.len()) }
230230
231231
/// Returns a vector containing all but the last element of a slice
232-
pub pure fn init<T:Copy>(v: &[const T]) -> ~[T] {
233-
assert len(v) != 0u;
234-
slice(v, 0u, len(v) - 1u).to_vec()
232+
pub pure fn init<T>(v: &r/[T]) -> &r/[T] { slice(v, 0, v.len() - 1) }
233+
234+
/// Returns a vector containing all but the last `n' elements of a slice
235+
pub pure fn initn<T>(v: &r/[T], n: uint) -> &r/[T] {
236+
slice(v, 0, v.len() - n)
235237
}
236238
237239
/// Returns the last element of the slice `v`, failing if the slice is empty.
@@ -1694,17 +1696,12 @@ impl<T> Container for &[const T] {
16941696
}
16951697

16961698
pub trait CopyableVector<T> {
1697-
pure fn init(&self) -> ~[T];
16981699
pure fn last(&self) -> T;
16991700
pure fn slice(&self, start: uint, end: uint) -> ~[T];
17001701
}
17011702

17021703
/// Extension methods for vectors
1703-
impl<T:Copy> CopyableVector<T> for &[const T] {
1704-
/// Returns all but the last elemnt of a vector
1705-
#[inline]
1706-
pure fn init(&self) -> ~[T] { init(*self) }
1707-
1704+
impl<T: Copy> CopyableVector<T> for &[const T] {
17081705
/// Returns the last element of a `v`, failing if the vector is empty.
17091706
#[inline]
17101707
pure fn last(&self) -> T { last(*self) }
@@ -1722,6 +1719,8 @@ pub trait ImmutableVector<T> {
17221719
pure fn head_opt(&self) -> Option<&self/T>;
17231720
pure fn tail(&self) -> &self/[T];
17241721
pure fn tailn(&self, n: uint) -> &self/[T];
1722+
pure fn init(&self) -> &self/[T];
1723+
pure fn initn(&self, n: uint) -> &self/[T];
17251724
pure fn foldr<U: Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U;
17261725
pure fn map<U>(&self, f: fn(t: &T) -> U) -> ~[U];
17271726
pure fn mapi<U>(&self, f: fn(uint, t: &T) -> U) -> ~[U];
@@ -1755,6 +1754,14 @@ impl<T> ImmutableVector<T> for &[T] {
17551754
#[inline]
17561755
pure fn tailn(&self, n: uint) -> &self/[T] { tailn(*self, n) }
17571756

1757+
/// Returns all but the last elemnt of a vector
1758+
#[inline]
1759+
pure fn init(&self) -> &self/[T] { init(*self) }
1760+
1761+
/// Returns all but the last `n' elemnts of a vector
1762+
#[inline]
1763+
pure fn initn(&self, n: uint) -> &self/[T] { initn(*self, n) }
1764+
17581765
/// Reduce a vector from right to left
17591766
#[inline]
17601767
pure fn foldr<U:Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U {
@@ -2638,6 +2645,38 @@ mod tests {
26382645
a.tailn(2);
26392646
}
26402647

2648+
#[test]
2649+
fn test_init() {
2650+
let mut a = ~[11];
2651+
assert a.init() == &[];
2652+
a = ~[11, 12];
2653+
assert a.init() == &[11];
2654+
}
2655+
2656+
#[init]
2657+
#[should_fail]
2658+
#[ignore(cfg(windows))]
2659+
fn test_init_empty() {
2660+
let a: ~[int] = ~[];
2661+
a.init();
2662+
}
2663+
2664+
#[test]
2665+
fn test_initn() {
2666+
let mut a = ~[11, 12, 13];
2667+
assert a.initn(0) == &[11, 12, 13];
2668+
a = ~[11, 12, 13];
2669+
assert a.initn(2) == &[11];
2670+
}
2671+
2672+
#[init]
2673+
#[should_fail]
2674+
#[ignore(cfg(windows))]
2675+
fn test_initn_empty() {
2676+
let a: ~[int] = ~[];
2677+
a.initn(2);
2678+
}
2679+
26412680
#[test]
26422681
fn test_last() {
26432682
let mut n = last_opt(~[]);
@@ -3317,12 +3356,6 @@ mod tests {
33173356
assert (v2[1] == 10);
33183357
}
33193358

3320-
#[test]
3321-
fn test_init() {
3322-
let v = init(~[1, 2, 3]);
3323-
assert v == ~[1, 2];
3324-
}
3325-
33263359
#[test]
33273360
fn test_split() {
33283361
fn f(x: &int) -> bool { *x == 3 }
@@ -3387,13 +3420,6 @@ mod tests {
33873420
(~[], ~[1, 2, 3]);
33883421
}
33893422

3390-
#[test]
3391-
#[should_fail]
3392-
#[ignore(cfg(windows))]
3393-
fn test_init_empty() {
3394-
init::<int>(~[]);
3395-
}
3396-
33973423
#[test]
33983424
fn test_concat() {
33993425
assert concat(~[~[1], ~[2,3]]) == ~[1, 2, 3];

branches/try2/src/librustc/metadata/decoder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,18 @@ pub fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt,
558558
-> csearch::found_ast {
559559
debug!("Looking up item: %d", id);
560560
let item_doc = lookup_item(id, cdata.data);
561-
let path = vec::init(item_path(intr, item_doc));
561+
let path = {
562+
let item_path = item_path(intr, item_doc);
563+
vec::from_slice(item_path.init())
564+
};
562565
match decode_inlined_item(cdata, tcx, path, item_doc) {
563566
Some(ref ii) => csearch::found((/*bad*/copy *ii)),
564567
None => {
565568
match item_parent_item(item_doc) {
566569
Some(did) => {
567570
let did = translate_def_id(cdata, did);
568571
let parent_item = lookup_item(did.node, cdata.data);
569-
match decode_inlined_item(cdata, tcx, path,
570-
parent_item) {
572+
match decode_inlined_item(cdata, tcx, path, parent_item) {
571573
Some(ref ii) => csearch::found_parent(did, (/*bad*/copy *ii)),
572574
None => csearch::not_found
573575
}

branches/try2/src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3815,7 +3815,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
38153815
}
38163816

38173817
ast_map::node_variant(ref variant, _, path) => {
3818-
vec::append_one(vec::init(*path),
3818+
vec::append_one(vec::from_slice(vec::init(*path)),
38193819
ast_map::path_name((*variant).node.name))
38203820
}
38213821

0 commit comments

Comments
 (0)