From ad16fecc332e5dd39236f43c491c009ea798352b Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 10 Mar 2013 20:11:10 -0400 Subject: [PATCH] treemap: inline the TreeSet wrappers --- src/libstd/treemap.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 45ae11ed7694..9cef77cfa764 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -77,21 +77,13 @@ pure fn lt(a: &TreeMap, impl Ord for TreeMap { #[inline(always)] - pure fn lt(&self, other: &TreeMap) -> bool { - lt(self, other) - } + pure fn lt(&self, other: &TreeMap) -> bool { lt(self, other) } #[inline(always)] - pure fn le(&self, other: &TreeMap) -> bool { - !lt(other, self) - } + pure fn le(&self, other: &TreeMap) -> bool { !lt(other, self) } #[inline(always)] - pure fn ge(&self, other: &TreeMap) -> bool { - !lt(self, other) - } + pure fn ge(&self, other: &TreeMap) -> bool { !lt(self, other) } #[inline(always)] - pure fn gt(&self, other: &TreeMap) -> bool { - lt(other, self) - } + pure fn gt(&self, other: &TreeMap) -> bool { lt(other, self) } } impl<'self, K: TotalOrd, V> BaseIter<(&'self K, &'self V)> for TreeMap { @@ -244,19 +236,24 @@ pub struct TreeSet { impl BaseIter for TreeSet { /// Visit all values in order + #[inline(always)] pure fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) } + #[inline(always)] pure fn size_hint(&self) -> Option { Some(self.len()) } } impl ReverseIter for TreeSet { /// Visit all values in reverse order + #[inline(always)] pure fn each_reverse(&self, f: &fn(&T) -> bool) { self.map.each_key_reverse(f) } } impl Eq for TreeSet { + #[inline(always)] pure fn eq(&self, other: &TreeSet) -> bool { self.map == other.map } + #[inline(always)] pure fn ne(&self, other: &TreeSet) -> bool { self.map != other.map } } @@ -273,29 +270,35 @@ impl Ord for TreeSet { impl Container for TreeSet { /// Return the number of elements in the set + #[inline(always)] pure fn len(&self) -> uint { self.map.len() } /// Return true if the set contains no elements + #[inline(always)] pure fn is_empty(&self) -> bool { self.map.is_empty() } } impl Mutable for TreeSet { /// Clear the set, removing all values. + #[inline(always)] fn clear(&mut self) { self.map.clear() } } impl Set for TreeSet { /// Return true if the set contains a value + #[inline(always)] pure fn contains(&self, value: &T) -> bool { self.map.contains_key(value) } /// Add a value to the set. Return true if the value was not already /// present in the set. + #[inline(always)] fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) } /// Remove a value from the set. Return true if the value was /// present in the set. + #[inline(always)] fn remove(&mut self, value: &T) -> bool { self.map.remove(value) } /// Return true if the set has no elements in common with `other`. @@ -320,6 +323,7 @@ impl Set for TreeSet { } /// Return true if the set is a subset of another + #[inline(always)] pure fn is_subset(&self, other: &TreeSet) -> bool { other.is_superset(self) } @@ -488,10 +492,12 @@ impl Set for TreeSet { pub impl TreeSet { /// Create an empty TreeSet + #[inline(always)] static pure fn new() -> TreeSet { TreeSet{map: TreeMap::new()} } /// Get a lazy iterator over the values in the set. /// Requires that it be frozen (immutable). + #[inline(always)] pure fn iter(&self) -> TreeSetIterator/&self { TreeSetIterator{iter: self.map.iter()} } @@ -504,11 +510,13 @@ pub struct TreeSetIterator { /// Advance the iterator to the next node (in order). If this iterator is /// finished, does nothing. +#[inline(always)] pub fn set_next(iter: &mut TreeSetIterator/&r) -> Option<&r/T> { do map_next(&mut iter.iter).map |&(value, _)| { value } } /// Advance the iterator through the set +#[inline(always)] pub fn set_advance(iter: &mut TreeSetIterator/&r, f: &fn(&r/T) -> bool) { do map_advance(&mut iter.iter) |(k, _)| { f(k) }