diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-05-22 10:54:12 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-07-02 18:30:12 -0700 |
| commit | f093d374edb89aedc940468d3d789dd95cec6347 (patch) | |
| tree | 8d9197ba35866b536c4a5ed8178f69387e4a69af /src/libcore/dvec.rs | |
| parent | 0b1edb7f0e25cae2a1f519af17bfc76682af0e14 (diff) | |
rustc: Implement a new resolve pass behind a compile flag
Diffstat (limited to 'src/libcore/dvec.rs')
| -rw-r--r-- | src/libcore/dvec.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index ea67947073e..f753fa739ae 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -200,6 +200,7 @@ impl extensions<A:copy> for dvec<A> { } } + /* #[doc = " Append all elements of an iterable. @@ -222,6 +223,7 @@ impl extensions<A:copy> for dvec<A> { v } } + */ #[doc = " Gets a copy of the current contents. @@ -267,7 +269,28 @@ impl extensions<A:copy> for dvec<A> { } #[doc = "Returns the last element, failing if the vector is empty"] + #[inline(always)] fn last() -> A { - self.get_elt(self.len() - 1u) + self.check_not_borrowed(); + + let length = self.len(); + if length == 0u { + fail "attempt to retrieve the last element of an empty vector"; + } + + ret self.data[length - 1u]; + } + + #[doc="Iterates over the elements in reverse order"] + #[inline(always)] + fn reach(f: fn(A) -> bool) { + let length = self.len(); + let mut i = 0u; + while i < length { + if !f(self.get_elt(i)) { + break; + } + i += 1u; + } } } |
