diff options
author | Ty Overby <ty@pre-alpha.com> | 2015-01-01 23:09:16 -0800 |
---|---|---|
committer | Ty Overby <ty@pre-alpha.com> | 2015-01-01 23:44:02 -0800 |
commit | a698146943bcd6df2a61bbfd56badf3018662709 (patch) | |
tree | b2cc041b67dd54f64c6123981bffbd0201f9620a /src/android/mod.rs | |
parent | f68bf85a85ceb416f714bc36ff5aa5c6ae65c008 (diff) | |
download | glutin-a698146943bcd6df2a61bbfd56badf3018662709.tar.gz glutin-a698146943bcd6df2a61bbfd56badf3018662709.zip |
Change the way that events are represented.
The bulk of this commit is changing instances of Vec to RingBuf which is
optimized for the push_back() / pop_front() strategy that is used
internaly in the event system.
The glutin custom iterators are now just wrappers around the RingBuf
iterator type. This will bring the running time of iterator traversal from
O(n^2) to O(n) because shifting-on-delete won't be performed.
Diffstat (limited to 'src/android/mod.rs')
-rw-r--r-- | src/android/mod.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/android/mod.rs b/src/android/mod.rs index b8514f1..c548f2f 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -7,6 +7,8 @@ use events::ElementState::{Pressed, Released}; use events::Event::{MouseInput, MouseMoved}; use events::MouseButton::LeftMouseButton; +use std::collections::RingBuf; + use BuilderAttribs; pub struct Window { @@ -20,8 +22,10 @@ pub struct MonitorID; mod ffi; -pub fn get_available_monitors() -> Vec<MonitorID> { - vec![ MonitorID ] +pub fn get_available_monitors() -> RingBuf <MonitorID> { + let rb = RingBuf::new(); + rb.push_back(MonitorId); + rb } pub fn get_primary_monitor() -> MonitorID { @@ -215,19 +219,19 @@ impl Window { WindowProxy } - pub fn poll_events(&self) -> Vec<Event> { - let mut events = Vec::new(); + pub fn poll_events(&self) -> RingBuf<Event> { + let mut events = RingBuf::new(); loop { match self.event_rx.try_recv() { Ok(event) => match event { android_glue::Event::EventDown => { - events.push(MouseInput(Pressed, LeftMouseButton)); + events.push_back(MouseInput(Pressed, LeftMouseButton)); }, android_glue::Event::EventUp => { - events.push(MouseInput(Released, LeftMouseButton)); + events.push_back(MouseInput(Released, LeftMouseButton)); }, android_glue::Event::EventMove(x, y) => { - events.push(MouseMoved((x as int, y as int))); + events.push_back(MouseMoved((x as int, y as int))); }, }, Err(_) => { @@ -238,7 +242,7 @@ impl Window { events } - pub fn wait_events(&self) -> Vec<Event> { + pub fn wait_events(&self) -> RingBuf<Event> { use std::time::Duration; use std::io::timer; timer::sleep(Duration::milliseconds(16)); |