about summary refs log tree commit diff
path: root/src/libstd/container.rs
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2013-07-25 04:02:08 -0400
committerSteven Fackler <sfackler@gmail.com>2013-07-25 15:17:30 -0700
commitfeb18fe8daa3952718c29039ec792d5e69d1276f (patch)
treec3d3d6143b8ae1c9765033a29b193f85dc0dd860 /src/libstd/container.rs
parentb1f5b1ba5fd12a058d153e9da8f11cd1bc597bf0 (diff)
Added default impls for container methods
A couple of implementations of Container::is_empty weren't exactly
self.len() == 0 so I left them alone (e.g. Treemap).
Diffstat (limited to 'src/libstd/container.rs')
-rw-r--r--src/libstd/container.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libstd/container.rs b/src/libstd/container.rs
index 4bad28ca338..d855beea50b 100644
--- a/src/libstd/container.rs
+++ b/src/libstd/container.rs
@@ -19,7 +19,10 @@ pub trait Container {
     fn len(&self) -> uint;
 
     /// Return true if the container contains no elements
-    fn is_empty(&self) -> bool;
+    #[inline]
+    fn is_empty(&self) -> bool {
+        self.len() == 0
+    }
 }
 
 /// A trait to represent mutable containers
@@ -43,11 +46,17 @@ pub trait MutableMap<K, V>: Map<K, V> + Mutable {
     /// Insert a key-value pair into the map. An existing value for a
     /// key is replaced by the new value. Return true if the key did
     /// not already exist in the map.
-    fn insert(&mut self, key: K, value: V) -> bool;
+    #[inline]
+    fn insert(&mut self, key: K, value: V) -> bool {
+        self.swap(key, value).is_none()
+    }
 
     /// Remove a key-value pair from the map. Return true if the key
     /// was present in the map, otherwise false.
-    fn remove(&mut self, key: &K) -> bool;
+    #[inline]
+    fn remove(&mut self, key: &K) -> bool {
+        self.pop(key).is_some()
+    }
 
     /// Insert a key-value pair from the map. If the key already had a value
     /// present in the map, that value is returned. Otherwise None is returned.