From 5b593a3d3264599fb83e6ab2c2ffe2d14078057c Mon Sep 17 00:00:00 2001 From: Aneesh Agrawal Date: Fri, 10 Apr 2015 18:59:02 -0400 Subject: [PATCH 1/2] Switch Arc> to Arc for perf boost. Image used to be a trait, but no longer is, so boxing it is no longer necessary. --- components/gfx/display_list/mod.rs | 2 +- components/gfx/paint_context.rs | 2 +- components/layout/display_list_builder.rs | 4 ++-- components/net/image_cache_task.rs | 6 +++--- components/net_traits/image/holder.rs | 6 +++--- components/net_traits/image_cache_task.rs | 4 ++-- components/script/dom/canvasrenderingcontext2d.rs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 85ca1549a63..b5b935c88d2 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -833,7 +833,7 @@ pub enum TextOrientation { #[derive(Clone)] pub struct ImageDisplayItem { pub base: BaseDisplayItem, - pub image: Arc>, + pub image: Arc, /// The dimensions to which the image display item should be stretched. If this is smaller than /// the bounds of this display item, then the image will be repeated in the appropriate diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 0cbd5a739b6..7f2ab8f9a55 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -129,7 +129,7 @@ impl<'a> PaintContext<'a> { pub fn draw_image(&self, bounds: &Rect, - image: Arc>, + image: Arc, image_rendering: image_rendering::T) { let size = Size2D(image.width as i32, image.height as i32); let (pixel_width, pixels, source_format) = match image.pixels { diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index edef3c31521..f440424cf1a 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -414,7 +414,7 @@ impl FragmentDisplayListBuilding for Fragment { // Use `background-size` to get the size. let mut bounds = *absolute_bounds; - let image_size = self.compute_background_image_size(style, &bounds, &**image); + let image_size = self.compute_background_image_size(style, &bounds, &*image); // Clip. // @@ -1016,7 +1016,7 @@ impl FragmentDisplayListBuilding for Fragment { &*self.style, Cursor::DefaultCursor), (*clip).clone()), - image: Arc::new(box png::Image { + image: Arc::new(png::Image { width: width as u32, height: height as u32, pixels: PixelsByColorType::RGBA8(canvas_data), diff --git a/components/net/image_cache_task.rs b/components/net/image_cache_task.rs index a97d29b8d66..d5fedb7bca2 100644 --- a/components/net/image_cache_task.rs +++ b/components/net/image_cache_task.rs @@ -110,7 +110,7 @@ enum ImageState { Prefetching(AfterPrefetch), Prefetched(Vec), Decoding, - Decoded(Arc>), + Decoded(Arc), Failed } @@ -303,7 +303,7 @@ impl ImageCache { load_from_memory(&data) }); - let image = image.map(|image| Arc::new(box image)); + let image = image.map(|image| Arc::new(image)); to_cache.send(Msg::StoreImage(url.clone(), image)).unwrap(); debug!("image_cache_task: ended image decode for {}", url.serialize()); }); @@ -317,7 +317,7 @@ impl ImageCache { } } - fn store_image(&mut self, url: Url, image: Option>>) { + fn store_image(&mut self, url: Url, image: Option>) { match self.get_state(&url) { ImageState::Decoding => { diff --git a/components/net_traits/image/holder.rs b/components/net_traits/image/holder.rs index e3bd1499032..6e79694f1dc 100644 --- a/components/net_traits/image/holder.rs +++ b/components/net_traits/image/holder.rs @@ -19,7 +19,7 @@ use url::Url; #[derive(Clone)] pub struct ImageHolder { url: Url, - image: Option>>, + image: Option>, cached_size: Size2D, local_image_cache: Arc>>, } @@ -68,12 +68,12 @@ impl ImageHolder { }) } - pub fn get_image_if_present(&self) -> Option>> { + pub fn get_image_if_present(&self) -> Option> { debug!("get_image_if_present() {}", self.url.serialize()); self.image.clone() } - pub fn get_image(&mut self, node_address: NodeAddress) -> Option>> { + pub fn get_image(&mut self, node_address: NodeAddress) -> Option> { debug!("get_image() {}", self.url.serialize()); // If this is the first time we've called this function, load diff --git a/components/net_traits/image_cache_task.rs b/components/net_traits/image_cache_task.rs index 3dfbed3fde6..852b4ad9c71 100644 --- a/components/net_traits/image_cache_task.rs +++ b/components/net_traits/image_cache_task.rs @@ -31,7 +31,7 @@ pub enum Msg { StorePrefetchedImageData(Url, Result, ()>), /// Used by the decoder tasks to post decoded images back to the cache - StoreImage(Url, Option>>), + StoreImage(Url, Option>), /// For testing WaitForStore(Sender<()>), @@ -42,7 +42,7 @@ pub enum Msg { #[derive(Clone)] pub enum ImageResponseMsg { - ImageReady(Arc>), + ImageReady(Arc), ImageNotReady, ImageFailed } diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 17dda025def..32db448af01 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -245,7 +245,7 @@ impl CanvasRenderingContext2D { return Some((image_data, image_size)); } - fn request_image_from_cache(&self, url: Url) -> Option>> { + fn request_image_from_cache(&self, url: Url) -> Option> { let canvas = self.canvas.root(); let window = window_from_node(canvas.r()).root(); let window = window.r(); From 395e8a598111213ba08b53b2930c8dc18ad98dfd Mon Sep 17 00:00:00 2001 From: Aneesh Agrawal Date: Mon, 13 Apr 2015 17:23:03 -0400 Subject: [PATCH 2/2] Make minor syntax simplification to address review. --- components/net/image_cache_task.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/net/image_cache_task.rs b/components/net/image_cache_task.rs index d5fedb7bca2..0eeff0820c8 100644 --- a/components/net/image_cache_task.rs +++ b/components/net/image_cache_task.rs @@ -303,7 +303,7 @@ impl ImageCache { load_from_memory(&data) }); - let image = image.map(|image| Arc::new(image)); + let image = image.map(Arc::new); to_cache.send(Msg::StoreImage(url.clone(), image)).unwrap(); debug!("image_cache_task: ended image decode for {}", url.serialize()); });