Bug 1557721 - Use unwrap_or_else where possible. r=kvark
authorBruce Mitchener <bruce.mitchener@gmail.com>
Fri, 07 Jun 2019 16:17:07 +0000
changeset 477879 a18263c690b31c1629fed59b67300730ad0dd2e5
parent 477878 df0f7465489c6724f3f10545b1f17f07febceb4b
child 477880 1d9c323e12cef1ee5878bc65c4ad8cd17bd9a889
push id36125
push userapavel@mozilla.com
push dateFri, 07 Jun 2019 22:00:07 +0000
treeherdermozilla-central@d820bbb356aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskvark
bugs1557721
milestone69.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 1557721 - Use unwrap_or_else where possible. r=kvark [wrupdater] From https://github.com/servo/webrender/pull/3667 Depends on D34160 Differential Revision: https://phabricator.services.mozilla.com/D34161
gfx/wr/webrender/src/border.rs
gfx/wr/webrender/src/device/gl.rs
gfx/wr/webrender/src/display_list_flattener.rs
gfx/wr/webrender/src/picture.rs
gfx/wr/webrender/src/prim_store/mod.rs
gfx/wr/webrender/src/resource_cache.rs
gfx/wr/webrender_api/src/image.rs
--- a/gfx/wr/webrender/src/border.rs
+++ b/gfx/wr/webrender/src/border.rs
@@ -1060,17 +1060,17 @@ fn add_corner_segment(
         return;
     }
 
     if side0.style.is_hidden() && side1.style.is_hidden() {
         return;
     }
 
     let segment_rect = image_rect.intersection(&non_overlapping_rect)
-        .unwrap_or(LayoutRect::zero());
+        .unwrap_or_else(LayoutRect::zero);
 
     if segment_rect.size.width <= 0. || segment_rect.size.height <= 0. {
         return;
     }
 
     let texture_rect = segment_rect
         .translate(&-image_rect.origin.to_vector())
         .scale(1.0 / image_rect.size.width, 1.0 / image_rect.size.height);
--- a/gfx/wr/webrender/src/device/gl.rs
+++ b/gfx/wr/webrender/src/device/gl.rs
@@ -2208,17 +2208,17 @@ impl Device {
                     DeviceIntPoint::new(
                         dest_rect.min_x().min(dest_rect.max_x()),
                         dest_rect.min_y().min(dest_rect.max_y()),
                     ),
                     DeviceIntSize::new(
                         dest_rect.size.width.abs(),
                         dest_rect.size.height.abs(),
                     ),
-                ).intersection(&dimensions.into()).unwrap_or(DeviceIntRect::zero());
+                ).intersection(&dimensions.into()).unwrap_or_else(DeviceIntRect::zero);
 
                 self.bind_read_target_impl(fbo);
                 self.bind_texture_impl(
                     DEFAULT_TEXTURE,
                     id,
                     target,
                 );
 
--- a/gfx/wr/webrender/src/display_list_flattener.rs
+++ b/gfx/wr/webrender/src/display_list_flattener.rs
@@ -2443,17 +2443,17 @@ impl<'a> DisplayListFlattener<'a> {
                     }
                 };
                 let clip_rect = LayoutRect::new(
                     info.rect.origin,
                     clip_size,
                 );
                 info.clip_rect = clip_rect
                     .intersection(&info.clip_rect)
-                    .unwrap_or(LayoutRect::zero());
+                    .unwrap_or_else(LayoutRect::zero);
             }
 
             LineDecorationCacheKey {
                 style,
                 orientation,
                 wavy_line_thickness: Au::from_f32_px(wavy_line_thickness),
                 size: size.to_au(),
             }
--- a/gfx/wr/webrender/src/picture.rs
+++ b/gfx/wr/webrender/src/picture.rs
@@ -819,17 +819,17 @@ impl TileCache {
                 frame_context.clip_scroll_tree,
             );
 
             // Attempt to correlate them to work out which offset to apply.
             correlate_prim_maps(
                 &frame_state.retained_tiles.ref_prims,
                 &new_prim_map,
             )
-        }.unwrap_or(WorldVector2D::zero());
+        }.unwrap_or_else(WorldVector2D::zero);
 
         // Assume no tiles are valid to draw by default
         self.tiles_to_draw.clear();
 
         self.map_local_to_world = SpaceMapper::new(
             ROOT_SPATIAL_NODE_INDEX,
             frame_context.screen_world_rect,
         );
@@ -1178,17 +1178,17 @@ impl TileCache {
             }
         };
 
         // The transforms of any clips that are relative to the picture may affect
         // the content rendered by this primitive.
         let mut world_clip_rect = world_rect;
         let mut culling_rect = prim_rect
             .intersection(&prim_instance.local_clip_rect)
-            .unwrap_or(LayoutRect::zero());
+            .unwrap_or_else(LayoutRect::zero);
 
         // To maintain the previous logic, consider every clip in the current active
         // clip stack that could affect this primitive.
         // TODO(gw): We can make this much more efficient now, by taking advantage
         //           of the per-picture clip chain information, rather then considering
         //           it for every primitive, as we do here for simplicity.
         for clip_stack in &clip_chain_stack.stack {
             for clip_chain_id in clip_stack {
@@ -1227,22 +1227,22 @@ impl TileCache {
                                 match self.map_local_to_world.map(&local_clip_rect) {
                                     Some(clip_world_rect) => {
                                         // Even if this ends up getting clipped out by the current clip
                                         // stack, we want to ensure the primitive gets added to the tiles
                                         // below, to ensure invalidation isn't tripped up by the wrong
                                         // number of primitives that affect this tile.
                                         world_clip_rect = world_clip_rect
                                             .intersection(&clip_world_rect)
-                                            .unwrap_or(WorldRect::zero());
+                                            .unwrap_or_else(WorldRect::zero);
 
                                         // If the clip rect is in the same spatial node, it can be handled by the
                                         // local clip rect.
                                         if clip_chain_node.spatial_node_index == prim_instance.spatial_node_index {
-                                            culling_rect = culling_rect.intersection(&local_clip_rect).unwrap_or(LayoutRect::zero());
+                                            culling_rect = culling_rect.intersection(&local_clip_rect).unwrap_or_else(LayoutRect::zero);
 
                                             false
                                         } else if !clip_scroll_tree.is_same_or_child_of(
                                             clip_chain_node.spatial_node_index,
                                             self.spatial_node_index,
                                         ) {
                                             // If the clip node is *not* a child of the main scroll root,
                                             // add it to the list of potential world clips to be checked later.
@@ -1325,17 +1325,17 @@ impl TileCache {
 
                 // Store the local clip rect by calculating what portion
                 // of the tile it covers.
                 let world_culling_rect = world_culling_rect
                     .intersection(&tile.world_rect)
                     .map(|rect| {
                         rect.translate(&-tile.world_rect.origin.to_vector())
                     })
-                    .unwrap_or(WorldRect::zero())
+                    .unwrap_or_else(WorldRect::zero)
                     .round();
 
                 // Work out the needed rect for the primitive on this tile.
                 // TODO(gw): We should be able to remove this for any tile that is not
                 //           a partially clipped tile, which would be a significant
                 //           optimization for the common case (non-clipped tiles).
 
                 // Mark if the tile is cacheable at all.
@@ -1552,17 +1552,17 @@ impl TileCache {
                         .get_texture_cache_item(&tile.handle);
 
                     let src_origin = (visible_rect.origin * frame_context.global_device_pixel_scale).round().to_i32();
                     let valid_rect = visible_rect.translate(&-tile.world_rect.origin.to_vector());
 
                     tile.valid_rect = visible_rect
                         .intersection(&self.world_bounding_rect)
                         .map(|rect| rect.translate(&-tile.world_rect.origin.to_vector()))
-                        .unwrap_or(WorldRect::zero());
+                        .unwrap_or_else(WorldRect::zero);
 
                     // Store a blit operation to be done after drawing the
                     // frame in order to update the cached texture tile.
                     let dest_rect = (valid_rect * frame_context.global_device_pixel_scale).round().to_i32();
                     self.pending_blits.push(TileBlit {
                         target: cache_item,
                         src_offset: src_origin,
                         dest_offset: dest_rect.origin,
@@ -1824,17 +1824,17 @@ impl SurfaceInfo {
             ROOT_SPATIAL_NODE_INDEX,
             surface_spatial_node_index,
             world_rect,
             clip_scroll_tree,
         );
 
         let pic_bounds = map_surface_to_world
             .unmap(&map_surface_to_world.bounds)
-            .unwrap_or(PictureRect::max_rect());
+            .unwrap_or_else(PictureRect::max_rect);
 
         let map_local_to_surface = SpaceMapper::new(
             surface_spatial_node_index,
             pic_bounds,
         );
 
         SurfaceInfo {
             rect: PictureRect::zero(),
@@ -2102,17 +2102,17 @@ impl PrimitiveList {
             let cluster = &mut clusters[cluster_index];
             if !is_pic {
                 let prim_rect = LayoutRect::new(
                     prim_instance.prim_origin,
                     prim_data.prim_size,
                 );
                 let culling_rect = prim_instance.local_clip_rect
                     .intersection(&prim_rect)
-                    .unwrap_or(LayoutRect::zero());
+                    .unwrap_or_else(LayoutRect::zero);
 
                 cluster.bounding_rect = cluster.bounding_rect.union(&culling_rect);
             }
 
             prim_instance.cluster_index = ClusterIndex(cluster_index as u16);
         }
 
         PrimitiveList {
@@ -2403,17 +2403,17 @@ impl PicturePrimitive {
         let map_pic_to_world = SpaceMapper::new_with_target(
             ROOT_SPATIAL_NODE_INDEX,
             surface_spatial_node_index,
             frame_context.screen_world_rect,
             frame_context.clip_scroll_tree,
         );
 
         let pic_bounds = map_pic_to_world.unmap(&map_pic_to_world.bounds)
-                                         .unwrap_or(PictureRect::max_rect());
+                                         .unwrap_or_else(PictureRect::max_rect);
 
         let map_local_to_pic = SpaceMapper::new(
             surface_spatial_node_index,
             pic_bounds,
         );
 
         let (map_raster_to_world, map_pic_to_raster) = create_raster_mappers(
             surface_spatial_node_index,
@@ -3348,17 +3348,17 @@ fn create_raster_mappers(
     let map_raster_to_world = SpaceMapper::new_with_target(
         ROOT_SPATIAL_NODE_INDEX,
         raster_spatial_node_index,
         world_rect,
         clip_scroll_tree,
     );
 
     let raster_bounds = map_raster_to_world.unmap(&world_rect)
-                                           .unwrap_or(RasterRect::max_rect());
+                                           .unwrap_or_else(RasterRect::max_rect);
 
     let map_pic_to_raster = SpaceMapper::new_with_target(
         raster_spatial_node_index,
         surface_spatial_node_index,
         raster_bounds,
         clip_scroll_tree,
     );
 
--- a/gfx/wr/webrender/src/prim_store/mod.rs
+++ b/gfx/wr/webrender/src/prim_store/mod.rs
@@ -3227,17 +3227,17 @@ fn decompose_repeated_primitive(
     }
 }
 
 fn compute_conservative_visible_rect(
     local_clip_rect: &LayoutRect,
     map_local_to_pic: &SpaceMapper<LayoutPixel, PicturePixel>,
 ) -> LayoutRect {
     if let Some(local_bounds) = map_local_to_pic.get_conservative_local_bounds() {
-        return local_clip_rect.intersection(&local_bounds).unwrap_or(LayoutRect::zero())
+        return local_clip_rect.intersection(&local_bounds).unwrap_or_else(LayoutRect::zero)
     }
 
     *local_clip_rect
 }
 
 fn edge_flags_for_tile_spacing(tile_spacing: &LayoutSize) -> EdgeAaSegmentMask {
     let mut flags = EdgeAaSegmentMask::empty();
 
--- a/gfx/wr/webrender/src/resource_cache.rs
+++ b/gfx/wr/webrender/src/resource_cache.rs
@@ -1195,17 +1195,17 @@ impl ResourceCache {
                             dirty_rect.size.height,
                         ),
                     };
                     let dirty_tiles = compute_tile_range(
                         &dirty_rect,
                         tile_size,
                     );
 
-                    tiles = tiles.intersection(&dirty_tiles).unwrap_or(TileRange::zero());
+                    tiles = tiles.intersection(&dirty_tiles).unwrap_or_else(TileRange::zero);
                 }
 
                 let original_tile_range = tiles;
 
                 // This code tries to keep things sane if Gecko sends
                 // nonsensical blob image requests.
                 // Constant here definitely needs to be tweaked.
                 const MAX_TILES_PER_REQUEST: i32 = 512;
--- a/gfx/wr/webrender_api/src/image.rs
+++ b/gfx/wr/webrender_api/src/image.rs
@@ -419,28 +419,28 @@ where
 
     /// Intersects the dirty rects.
     pub fn intersection(&self, other: &Self) -> Self {
         use crate::DirtyRect::*;
 
         match (*self, *other) {
             (All, rect) | (rect, All)  => rect,
             (Partial(rect1), Partial(rect2)) => Partial(rect1.intersection(&rect2)
-                                                                   .unwrap_or(TypedRect::zero()))
+                                                                   .unwrap_or_else(TypedRect::zero))
         }
     }
 
     /// Converts the dirty rect into a subrect of the given one via intersection.
     pub fn to_subrect_of(&self, rect: &TypedRect<T, U>) -> TypedRect<T, U> {
         use crate::DirtyRect::*;
 
         match *self {
             All              => *rect,
             Partial(dirty_rect) => dirty_rect.intersection(rect)
-                                               .unwrap_or(TypedRect::zero()),
+                                               .unwrap_or_else(TypedRect::zero),
         }
     }
 }
 
 impl<T: Copy, U> Copy for DirtyRect<T, U> {}
 impl<T: Copy, U> Clone for DirtyRect<T, U> {
     fn clone(&self) -> Self { *self }
 }