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/lib.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/lib.rs')
-rw-r--r-- | src/lib.rs | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -43,6 +43,7 @@ extern crate core_graphics; pub use events::*; use std::default::Default; +use std::collections::ring_buf::IntoIter as RingBufIter; #[cfg(all(not(target_os = "windows"), not(target_os = "linux"), not(target_os = "macos"), not(target_os = "android")))] use this_platform_is_not_supported; @@ -97,7 +98,7 @@ pub struct WindowBuilder<'a> { attribs: BuilderAttribs<'a> } -/// Attributes +/// Attributes struct BuilderAttribs<'a> { headless: bool, strict: bool, @@ -487,7 +488,7 @@ impl Window { /// Contrary to `wait_events`, this function never blocks. #[inline] pub fn poll_events(&self) -> PollEventsIterator { - PollEventsIterator { data: self.window.poll_events() } + PollEventsIterator { data: self.window.poll_events().into_iter() } } /// Waits for an event, then returns an iterator to all the events that are currently @@ -497,7 +498,7 @@ impl Window { /// this function will block until there is one. #[inline] pub fn wait_events(&self) -> WaitEventsIterator { - WaitEventsIterator { data: self.window.wait_events() } + WaitEventsIterator { data: self.window.wait_events().into_iter() } } /// Sets the context as the current context. @@ -637,12 +638,12 @@ impl gl_common::GlFunctionsSource for HeadlessContext { // Implementation note: we retreive the list once, then serve each element by one by one. // This may change in the future. pub struct PollEventsIterator<'a> { - data: Vec<Event>, + data: RingBufIter<Event>, } impl<'a> Iterator<Event> for PollEventsIterator<'a> { fn next(&mut self) -> Option<Event> { - self.data.remove(0) + self.data.next() } } @@ -650,12 +651,12 @@ impl<'a> Iterator<Event> for PollEventsIterator<'a> { // Implementation note: we retreive the list once, then serve each element by one by one. // This may change in the future. pub struct WaitEventsIterator<'a> { - data: Vec<Event>, + data: RingBufIter<Event>, } impl<'a> Iterator<Event> for WaitEventsIterator<'a> { fn next(&mut self) -> Option<Event> { - self.data.remove(0) + self.data.next() } } @@ -664,13 +665,13 @@ impl<'a> Iterator<Event> for WaitEventsIterator<'a> { // This may change in the future. #[cfg(feature = "window")] pub struct AvailableMonitorsIter { - data: Vec<winimpl::MonitorID>, + data: RingBufIter<winimpl::MonitorID>, } #[cfg(feature = "window")] impl Iterator<MonitorID> for AvailableMonitorsIter { fn next(&mut self) -> Option<MonitorID> { - self.data.remove(0).map(|id| MonitorID(id)) + self.data.next().map(|id| MonitorID(id)) } } @@ -678,7 +679,7 @@ impl Iterator<MonitorID> for AvailableMonitorsIter { #[cfg(feature = "window")] pub fn get_available_monitors() -> AvailableMonitorsIter { let data = winimpl::get_available_monitors(); - AvailableMonitorsIter{ data: data } + AvailableMonitorsIter{ data: data.into_iter() } } /// Returns the primary monitor of the system. |