about summary refs log tree commit diff
path: root/src/libstd/io/signal.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-02-19 19:29:58 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-02-23 00:35:11 -0800
commit2a14e084cfd8cf9a9149d0b7c6329b0dad0521d0 (patch)
tree78090dacffcdda10a36a6e538f3f73d3d3a6e35c /src/libstd/io/signal.rs
parentedf351e9f7d17777b1385093bfa7b6654e662d44 (diff)
downloadrust-2a14e084cfd8cf9a9149d0b7c6329b0dad0521d0.tar.gz
rust-2a14e084cfd8cf9a9149d0b7c6329b0dad0521d0.zip
Move std::{trie, hashmap} to libcollections
These two containers are indeed collections, so their place is in
libcollections, not in libstd. There will always be a hash map as part of the
standard distribution of Rust, but by moving it out of the standard library it
makes libstd that much more portable to more platforms and environments.

This conveniently also removes the stuttering of 'std::hashmap::HashMap',
although 'collections::HashMap' is only one character shorter.
Diffstat (limited to 'src/libstd/io/signal.rs')
-rw-r--r--src/libstd/io/signal.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/libstd/io/signal.rs b/src/libstd/io/signal.rs
index 46c106234db..19aff4f70fe 100644
--- a/src/libstd/io/signal.rs
+++ b/src/libstd/io/signal.rs
@@ -20,12 +20,14 @@ definitions for a number of signals.
 */
 
 use clone::Clone;
-use result::{Ok, Err};
 use comm::{Port, Chan};
-use container::{Map, MutableMap};
-use hashmap;
 use io;
+use iter::Iterator;
+use mem::drop;
+use option::{Some, None};
+use result::{Ok, Err};
 use rt::rtio::{IoFactory, LocalIo, RtioSignal};
+use vec::{ImmutableVector, OwnedVector};
 
 #[repr(int)]
 #[deriving(Eq, IterBytes)]
@@ -78,7 +80,7 @@ pub enum Signum {
 /// ```
 pub struct Listener {
     /// A map from signums to handles to keep the handles in memory
-    priv handles: hashmap::HashMap<Signum, ~RtioSignal>,
+    priv handles: ~[(Signum, ~RtioSignal)],
     /// chan is where all the handles send signums, which are received by
     /// the clients from port.
     priv chan: Chan<Signum>,
@@ -97,7 +99,7 @@ impl Listener {
         Listener {
             chan: chan,
             port: port,
-            handles: hashmap::HashMap::new(),
+            handles: ~[],
         }
     }
 
@@ -118,14 +120,14 @@ impl Listener {
     /// If this function fails to register a signal handler, then an error will
     /// be returned.
     pub fn register(&mut self, signum: Signum) -> io::IoResult<()> {
-        if self.handles.contains_key(&signum) {
+        if self.handles.iter().any(|&(sig, _)| sig == signum) {
             return Ok(()); // self is already listening to signum, so succeed
         }
         match LocalIo::maybe_raise(|io| {
             io.signal(signum, self.chan.clone())
         }) {
             Ok(handle) => {
-                self.handles.insert(signum, handle);
+                self.handles.push((signum, handle));
                 Ok(())
             }
             Err(e) => Err(e)
@@ -137,7 +139,10 @@ impl Listener {
     /// notification about the signal. If the signal has already been received,
     /// it may still be returned by `recv`.
     pub fn unregister(&mut self, signum: Signum) {
-        self.handles.pop(&signum);
+        match self.handles.iter().position(|&(i, _)| i == signum) {
+            Some(i) => drop(self.handles.remove(i)),
+            None => {}
+        }
     }
 }