diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 1731de2691e..9eacddd9002 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -101,10 +101,12 @@ fn link_with_prev(mut next: ~Node, prev: Rawlink>) -> Link { impl Container for DList { /// O(1) + #[inline] fn is_empty(&self) -> bool { self.list_head.is_none() } /// O(1) + #[inline] fn len(&self) -> uint { self.length } @@ -114,6 +116,7 @@ impl Mutable for DList { /// Remove all elements from the DList /// /// O(N) + #[inline] fn clear(&mut self) { *self = DList::new() } @@ -121,21 +124,25 @@ impl Mutable for DList { impl Deque for DList { /// Provide a reference to the front element, or None if the list is empty + #[inline] fn front<'a>(&'a self) -> Option<&'a T> { self.list_head.map(|head| &head.value) } /// Provide a mutable reference to the front element, or None if the list is empty + #[inline] fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> { self.list_head.map_mut(|head| &mut head.value) } /// Provide a reference to the back element, or None if the list is empty + #[inline] fn back<'a>(&'a self) -> Option<&'a T> { self.list_tail.resolve_immut().map(|tail| &tail.value) } /// Provide a mutable reference to the back element, or None if the list is empty + #[inline] fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> { self.list_tail.resolve().map_mut(|tail| &mut tail.value) } @@ -158,7 +165,6 @@ impl Deque for DList { /// Remove the last element and return it, or None if the list is empty /// /// O(1) - #[inline] fn pop_back(&mut self) -> Option { match self.list_tail.resolve() { None => None, @@ -250,6 +256,7 @@ impl DList { /// Add all elements from `other` to the beginning of the list /// /// O(1) + #[inline] pub fn prepend(&mut self, mut other: DList) { util::swap(self, &mut other); self.append(other); @@ -259,7 +266,6 @@ impl DList { /// or at the end. /// /// O(N) - #[inline] pub fn insert_when(&mut self, elt: T, f: &fn(&T, &T) -> bool) { { let mut it = self.mut_iter(); @@ -300,16 +306,19 @@ impl DList { /// Provide a forward iterator + #[inline] pub fn iter<'a>(&'a self) -> DListIterator<'a, T> { DListIterator{nelem: self.len(), head: &self.list_head, tail: self.list_tail} } /// Provide a reverse iterator + #[inline] pub fn rev_iter<'a>(&'a self) -> InvertIterator<&'a T, DListIterator<'a, T>> { self.iter().invert() } /// Provide a forward iterator with mutable references + #[inline] pub fn mut_iter<'a>(&'a mut self) -> MutDListIterator<'a, T> { let head_raw = match self.list_head { Some(ref mut h) => Rawlink::some(*h), @@ -323,6 +332,7 @@ impl DList { } } /// Provide a reverse iterator with mutable references + #[inline] pub fn mut_rev_iter<'a>(&'a mut self) -> InvertIterator<&'a mut T, MutDListIterator<'a, T>> { self.mut_iter().invert() @@ -330,11 +340,13 @@ impl DList { /// Consume the list into an iterator yielding elements by value + #[inline] pub fn consume_iter(self) -> ConsumeIterator { ConsumeIterator{list: self} } /// Consume the list into an iterator yielding elements by value, in reverse + #[inline] pub fn consume_rev_iter(self) -> InvertIterator> { self.consume_iter().invert() } @@ -344,6 +356,7 @@ impl DList { /// Insert `elt` sorted in ascending order /// /// O(N) + #[inline] pub fn insert_ordered(&mut self, elt: T) { self.insert_when(elt, |a, b| a.cmp(b) != cmp::Less); } @@ -365,12 +378,14 @@ impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> { } } + #[inline] fn size_hint(&self) -> (uint, Option) { (self.nelem, Some(self.nelem)) } } impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> { + #[inline] fn next_back(&mut self) -> Option<&'self A> { if self.nelem == 0 { return None; @@ -405,6 +420,7 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> { } } + #[inline] fn size_hint(&self) -> (uint, Option) { (self.nelem, Some(self.nelem)) } @@ -457,6 +473,7 @@ impl<'self, A> ListInsertion for MutDListIterator<'self, A> { } } + #[inline] fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> { match self.head.resolve() { None => None, @@ -466,13 +483,17 @@ impl<'self, A> ListInsertion for MutDListIterator<'self, A> { } impl Iterator for ConsumeIterator { + #[inline] fn next(&mut self) -> Option { self.list.pop_front() } + + #[inline] fn size_hint(&self) -> (uint, Option) { (self.list.length, Some(self.list.length)) } } impl DoubleEndedIterator for ConsumeIterator { + #[inline] fn next_back(&mut self) -> Option { self.list.pop_back() } } @@ -489,6 +510,8 @@ impl Eq for DList { self.len() == other.len() && self.iter().zip(other.iter()).all(|(a, b)| a.eq(b)) } + + #[inline] fn ne(&self, other: &DList) -> bool { !self.eq(other) }