servo: Merge #8385 - Use more iterators in compositing component (from frewsxcv:compositing-iterators); r=Manishearth
authorCorey Farwell <coreyf@rwell.org>
Sat, 07 Nov 2015 10:04:02 +0500
changeset 337526 62671f0823137cfbf0f989643fe91b3af9e87fe2
parent 337525 2d17278e8862b552586ed660280ffd010f52e1c4
child 337527 fe7a508edf00d6b9de059ebde38cb101648d967b
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
servo: Merge #8385 - Use more iterators in compositing component (from frewsxcv:compositing-iterators); r=Manishearth Source-Repo: https://github.com/servo/servo Source-Revision: 3510cec3e511fb1dacf7b68e5a08bb64b221fc43
servo/components/compositing/compositor.rs
servo/components/compositing/surface_map.rs
--- a/servo/components/compositing/compositor.rs
+++ b/servo/components/compositing/compositor.rs
@@ -2026,23 +2026,21 @@ impl<Window: WindowMethods> IOCompositor
                 find_layer_with_pipeline_and_layer_id_for_layer(layer.clone(),
                                                                 pipeline_id,
                                                                 layer_id),
 
             None => None,
         }
     }
 
-    pub fn cache_unused_buffers(&mut self, buffers: Vec<Box<LayerBuffer>>) {
-        if !buffers.is_empty() {
-            let surfaces = buffers.into_iter().map(|buffer| {
-                buffer.native_surface
-            }).collect();
-            self.surface_map.insert_surfaces(&self.native_display, surfaces);
-        }
+    pub fn cache_unused_buffers<B>(&mut self, buffers: B)
+        where B: IntoIterator<Item=Box<LayerBuffer>>
+    {
+        let surfaces = buffers.into_iter().map(|buffer| buffer.native_surface);
+        self.surface_map.insert_surfaces(&self.native_display, surfaces);
     }
 
     #[allow(dead_code)]
     fn dump_layer_tree(&self) {
         if !opts::get().dump_layer_tree {
             return;
         }
 
--- a/servo/components/compositing/surface_map.rs
+++ b/servo/components/compositing/surface_map.rs
@@ -63,17 +63,19 @@ impl SurfaceMap {
         SurfaceMap {
             map: HashMap::new(),
             mem: 0,
             max_mem: max_mem,
             counter: 0,
         }
     }
 
-    pub fn insert_surfaces(&mut self, display: &NativeDisplay, surfaces: Vec<NativeSurface>) {
+    pub fn insert_surfaces<I>(&mut self, display: &NativeDisplay, surfaces: I)
+        where I: IntoIterator<Item=NativeSurface>
+    {
         for surface in surfaces {
             self.insert(display, surface);
         }
     }
 
     /// Insert a new buffer into the map.
     pub fn insert(&mut self, display: &NativeDisplay, mut new_surface: NativeSurface) {
         let new_key = SurfaceKey::get(new_surface.get_size());