From a698146943bcd6df2a61bbfd56badf3018662709 Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Thu, 1 Jan 2015 23:09:16 -0800 Subject: 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. --- src/x11/window/monitor.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/x11/window/monitor.rs') diff --git a/src/x11/window/monitor.rs b/src/x11/window/monitor.rs index f62a8ef..596dca7 100644 --- a/src/x11/window/monitor.rs +++ b/src/x11/window/monitor.rs @@ -1,10 +1,11 @@ -use std::{ptr}; +use std::ptr; +use std::collections::RingBuf; use super::super::ffi; use super::ensure_thread_init; pub struct MonitorID(pub uint); -pub fn get_available_monitors() -> Vec { +pub fn get_available_monitors() -> RingBuf { ensure_thread_init(); let nb_monitors = unsafe { let display = ffi::XOpenDisplay(ptr::null()); @@ -16,9 +17,9 @@ pub fn get_available_monitors() -> Vec { nb_monitors }; - let mut vec = Vec::new(); - vec.grow_fn(nb_monitors as uint, |i| MonitorID(i)); - vec + let mut monitors = RingBuf::new(); + monitors.extend(range(0, nb_monitors).map(|i| MonitorID(i as uint))); + monitors } pub fn get_primary_monitor() -> MonitorID { -- cgit v1.2.3