Bug 1607697 - Address unwrap_or_else(callback) and functions in callback clippy lints. r=Gankro
☠☠ backed out by c2dd65b196d3 ☠ ☠
authorNicolas Silva <nsilva@mozilla.com>
Wed, 08 Jan 2020 15:40:47 +0000
changeset 509365 d70cc2bb33f62aab04ee8a5ae5a086bcee5ab974
parent 509364 8490fa04e0eec09cbbd6c7b3301af05592d6fd6f
child 509366 6101f5e31e46f6c77198c66e14a56ea2510e7c92
push id36995
push userapavel@mozilla.com
push dateWed, 08 Jan 2020 21:56:06 +0000
treeherdermozilla-central@374a48ce8690 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGankro
bugs1607697
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1607697 - Address unwrap_or_else(callback) and functions in callback clippy lints. r=Gankro I don't think it makes much of a difference but clippy is quite vocal about it. Differential Revision: https://phabricator.services.mozilla.com/D59114
gfx/wr/webrender/src/image.rs
gfx/wr/webrender/src/lib.rs
gfx/wr/webrender/src/picture.rs
gfx/wr/webrender/src/render_task.rs
gfx/wr/webrender/src/resource_cache.rs
gfx/wr/webrender/src/scene_building.rs
--- a/gfx/wr/webrender/src/image.rs
+++ b/gfx/wr/webrender/src/image.rs
@@ -595,17 +595,17 @@ pub fn compute_valid_tiles_if_bounds_cha
     tile_size: u16,
 ) -> Option<TileRange> {
     let intersection = prev_rect.intersection(new_rect);
 
     if intersection.is_none() {
         return Some(TileRange::zero());
     }
 
-    let intersection = intersection.unwrap_or(DeviceIntRect::zero());
+    let intersection = intersection.unwrap_or_else(DeviceIntRect::zero);
 
     let left = prev_rect.min_x() != new_rect.min_x();
     let right = prev_rect.max_x() != new_rect.max_x();
     let top = prev_rect.min_y() != new_rect.min_y();
     let bottom = prev_rect.max_y() != new_rect.max_y();
 
     if !left && !right && !top && !bottom {
         // Bounds have not changed.
--- a/gfx/wr/webrender/src/lib.rs
+++ b/gfx/wr/webrender/src/lib.rs
@@ -36,16 +36,19 @@ More information about [stacking context
 [`BuiltDisplayList`](api::BuiltDisplayList)s. These are obtained by finalizing a
 [`DisplayListBuilder`](api::DisplayListBuilder). These are used to draw your geometry. But it
 doesn't only contain trivial geometry, it can also store another
 [`StackingContext`](api::StackingContext), as they're nestable.
 
 [stacking_contexts]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
 */
 
+#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal, clippy::new_without_default, clippy::too_many_arguments))]
+
+
 // Cribbed from the |matches| crate, for simplicity.
 macro_rules! matches {
     ($expression:expr, $($pattern:tt)+) => {
         match $expression {
             $($pattern)+ => true,
             _ => false
         }
     }
--- a/gfx/wr/webrender/src/picture.rs
+++ b/gfx/wr/webrender/src/picture.rs
@@ -737,17 +737,17 @@ impl Tile {
         ctx: &TilePreUpdateContext,
     ) {
         self.rect = rect;
         self.invalidation_reason  = None;
 
         self.clipped_rect = self.rect
             .intersection(&ctx.local_rect)
             .and_then(|r| r.intersection(&ctx.local_clip_rect))
-            .unwrap_or(PictureRect::zero());
+            .unwrap_or_else(PictureRect::zero);
 
         self.world_rect = ctx.pic_to_world_mapper
             .map(&self.rect)
             .expect("bug: map local tile rect");
 
         // Check if this tile is currently on screen.
         self.is_visible = self.world_rect.intersects(&ctx.global_screen_world_rect);
 
@@ -933,17 +933,17 @@ impl Tile {
         // rect to be the size of the entire tile.
         if !self.is_valid && !supports_dirty_rects {
             self.dirty_rect = self.rect;
         }
 
         // Ensure that the dirty rect doesn't extend outside the local tile rect.
         self.dirty_rect = self.dirty_rect
             .intersection(&self.rect)
-            .unwrap_or(PictureRect::zero());
+            .unwrap_or_else(PictureRect::zero);
 
         // See if this tile is a simple color, in which case we can just draw
         // it as a rect, and avoid allocating a texture surface and drawing it.
         // TODO(gw): Initial native compositor interface doesn't support simple
         //           color tiles. We can definitely support this in DC, so this
         //           should be added as a follow up.
         let is_simple_prim =
             ctx.backdrop.kind.can_be_promoted_to_compositor_surface() &&
@@ -1823,17 +1823,17 @@ impl TileCacheInstance {
         // but have just recently gone off-screen. This means that we avoid re-drawing
         // tiles if the user is scrolling up and down small amounts, at the cost of
         // a bit of extra texture memory.
         let desired_rect_in_pic_space = screen_rect_in_pic_space
             .inflate(0.0, 3.0 * self.tile_size.height);
 
         let needed_rect_in_pic_space = desired_rect_in_pic_space
             .intersection(&pic_rect)
-            .unwrap_or(PictureRect::zero());
+            .unwrap_or_else(PictureRect::zero);
 
         let p0 = needed_rect_in_pic_space.origin;
         let p1 = needed_rect_in_pic_space.bottom_right();
 
         let x0 = (p0.x / local_tile_rect.size.width).floor() as i32;
         let x1 = (p1.x / local_tile_rect.size.width).ceil() as i32;
 
         let y0 = (p0.y / local_tile_rect.size.height).floor() as i32;
@@ -3606,17 +3606,17 @@ impl PicturePrimitive {
                     PictureCompositeMode::TileCache { .. } => {
                         let tile_cache = self.tile_cache.as_mut().unwrap();
                         let mut first = true;
 
                         // Get the overall world space rect of the picture cache. Used to clip
                         // the tile rects below for occlusion testing to the relevant area.
                         let local_clip_rect = tile_cache.local_rect
                             .intersection(&tile_cache.local_clip_rect)
-                            .unwrap_or(PictureRect::zero());
+                            .unwrap_or_else(PictureRect::zero);
 
                         let world_clip_rect = map_pic_to_world
                             .map(&local_clip_rect)
                             .expect("bug: unable to map clip rect");
 
                         for key in &tile_cache.tiles_to_draw {
                             let tile = tile_cache.tiles.get_mut(key).expect("bug: no tile found!");
 
--- a/gfx/wr/webrender/src/render_task.rs
+++ b/gfx/wr/webrender/src/render_task.rs
@@ -1447,39 +1447,39 @@ impl RenderTask {
                 uv_rect_kind,
             };
             image_source.write_gpu_blocks(&mut request);
         }
 
         if let RenderTaskKind::SvgFilter(ref mut filter_task) = self.kind {
             match filter_task.info {
                 SvgFilterInfo::ColorMatrix(ref matrix) => {
-                    let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(|| GpuCacheHandle::new());
+                    let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(GpuCacheHandle::new);
                     if let Some(mut request) = gpu_cache.request(handle) {
                         for i in 0..5 {
                             request.push([matrix[i*4], matrix[i*4+1], matrix[i*4+2], matrix[i*4+3]]);
                         }
                     }
                 }
                 SvgFilterInfo::DropShadow(color) |
                 SvgFilterInfo::Flood(color) => {
-                    let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(|| GpuCacheHandle::new());
+                    let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(GpuCacheHandle::new);
                     if let Some(mut request) = gpu_cache.request(handle) {
                         request.push(color.to_array());
                     }
                 }
                 SvgFilterInfo::ComponentTransfer(ref data) => {
-                    let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(|| GpuCacheHandle::new());
+                    let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(GpuCacheHandle::new);
                     if let Some(request) = gpu_cache.request(handle) {
                         data.update(request);
                     }
                 }
                 SvgFilterInfo::Composite(ref operator) => {
                     if let CompositeOperator::Arithmetic(k_vals) = operator {
-                        let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(|| GpuCacheHandle::new());
+                        let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(GpuCacheHandle::new);
                         if let Some(mut request) = gpu_cache.request(handle) {
                             request.push(*k_vals);
                         }
                     }
                 }
                 _ => {},
             }
         }
--- a/gfx/wr/webrender/src/resource_cache.rs
+++ b/gfx/wr/webrender/src/resource_cache.rs
@@ -932,17 +932,17 @@ impl ResourceCache {
                                 rect.origin -= tile_offset.to_vector();
 
                                 let tile_rect = compute_tile_size(
                                     &descriptor.size.into(),
                                     tile_size,
                                     tile,
                                 ).into();
 
-                                rect.intersection(&tile_rect).unwrap_or(DeviceIntRect::zero())
+                                rect.intersection(&tile_rect).unwrap_or_else(DeviceIntRect::zero)
                             })
                         }
                         (None, Some(..)) => DirtyRect::All,
                         _ => *dirty_rect,
                     };
                     entry.dirty_rect = entry.dirty_rect.union(&local_dirty_rect);
                 }
             }
@@ -1015,17 +1015,17 @@ impl ResourceCache {
                 &image.visible_rect,
                 visible_rect,
                 tile_size,
             );
         }
 
         match (image.valid_tiles_after_bounds_change, valid_tiles_after_bounds_change) {
             (Some(old), Some(ref mut new)) => {
-                *new = new.intersection(&old).unwrap_or(TileRange::zero());
+                *new = new.intersection(&old).unwrap_or_else(TileRange::zero);
             }
             (Some(old), None) => {
                 valid_tiles_after_bounds_change = Some(old);
             }
             _ => {}
         }
 
         let blob_size = visible_rect.size;
--- a/gfx/wr/webrender/src/scene_building.rs
+++ b/gfx/wr/webrender/src/scene_building.rs
@@ -659,17 +659,17 @@ impl<'a> SceneBuilder<'a> {
             // occur while not scrolling (such as animation, video etc);
             let scroll_root = slice.cache_scroll_root.unwrap_or(ROOT_SPATIAL_NODE_INDEX);
 
             let instance = create_tile_cache(
                 slice_index,
                 scroll_root,
                 slice.prim_list,
                 background_color,
-                slice.shared_clips.unwrap_or(Vec::new()),
+                slice.shared_clips.unwrap_or_else(Vec::new),
                 &mut self.interners,
                 &mut self.prim_store,
                 &mut self.clip_store,
                 &mut self.picture_cache_spatial_nodes,
             );
 
             main_prim_list.add_prim(
                 instance,