Switch Arc<Box<Image>> to Arc<Image> for perf boost.

Image used to be a trait, but no longer is, so boxing it is no longer
necessary.
This commit is contained in:
Aneesh Agrawal 2015-04-10 18:59:02 -04:00
parent a8b0fb1e79
commit 5b593a3d32
7 changed files with 13 additions and 13 deletions

View file

@ -833,7 +833,7 @@ pub enum TextOrientation {
#[derive(Clone)] #[derive(Clone)]
pub struct ImageDisplayItem { pub struct ImageDisplayItem {
pub base: BaseDisplayItem, pub base: BaseDisplayItem,
pub image: Arc<Box<Image>>, pub image: Arc<Image>,
/// The dimensions to which the image display item should be stretched. If this is smaller than /// 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 /// the bounds of this display item, then the image will be repeated in the appropriate

View file

@ -129,7 +129,7 @@ impl<'a> PaintContext<'a> {
pub fn draw_image(&self, pub fn draw_image(&self,
bounds: &Rect<Au>, bounds: &Rect<Au>,
image: Arc<Box<Image>>, image: Arc<Image>,
image_rendering: image_rendering::T) { image_rendering: image_rendering::T) {
let size = Size2D(image.width as i32, image.height as i32); let size = Size2D(image.width as i32, image.height as i32);
let (pixel_width, pixels, source_format) = match image.pixels { let (pixel_width, pixels, source_format) = match image.pixels {

View file

@ -414,7 +414,7 @@ impl FragmentDisplayListBuilding for Fragment {
// Use `background-size` to get the size. // Use `background-size` to get the size.
let mut bounds = *absolute_bounds; 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. // Clip.
// //
@ -1016,7 +1016,7 @@ impl FragmentDisplayListBuilding for Fragment {
&*self.style, &*self.style,
Cursor::DefaultCursor), Cursor::DefaultCursor),
(*clip).clone()), (*clip).clone()),
image: Arc::new(box png::Image { image: Arc::new(png::Image {
width: width as u32, width: width as u32,
height: height as u32, height: height as u32,
pixels: PixelsByColorType::RGBA8(canvas_data), pixels: PixelsByColorType::RGBA8(canvas_data),

View file

@ -110,7 +110,7 @@ enum ImageState {
Prefetching(AfterPrefetch), Prefetching(AfterPrefetch),
Prefetched(Vec<u8>), Prefetched(Vec<u8>),
Decoding, Decoding,
Decoded(Arc<Box<Image>>), Decoded(Arc<Image>),
Failed Failed
} }
@ -303,7 +303,7 @@ impl ImageCache {
load_from_memory(&data) 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(); to_cache.send(Msg::StoreImage(url.clone(), image)).unwrap();
debug!("image_cache_task: ended image decode for {}", url.serialize()); 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<Arc<Box<Image>>>) { fn store_image(&mut self, url: Url, image: Option<Arc<Image>>) {
match self.get_state(&url) { match self.get_state(&url) {
ImageState::Decoding => { ImageState::Decoding => {

View file

@ -19,7 +19,7 @@ use url::Url;
#[derive(Clone)] #[derive(Clone)]
pub struct ImageHolder<NodeAddress> { pub struct ImageHolder<NodeAddress> {
url: Url, url: Url,
image: Option<Arc<Box<Image>>>, image: Option<Arc<Image>>,
cached_size: Size2D<u32>, cached_size: Size2D<u32>,
local_image_cache: Arc<Mutex<LocalImageCache<NodeAddress>>>, local_image_cache: Arc<Mutex<LocalImageCache<NodeAddress>>>,
} }
@ -68,12 +68,12 @@ impl<NodeAddress: Send + 'static> ImageHolder<NodeAddress> {
}) })
} }
pub fn get_image_if_present(&self) -> Option<Arc<Box<Image>>> { pub fn get_image_if_present(&self) -> Option<Arc<Image>> {
debug!("get_image_if_present() {}", self.url.serialize()); debug!("get_image_if_present() {}", self.url.serialize());
self.image.clone() self.image.clone()
} }
pub fn get_image(&mut self, node_address: NodeAddress) -> Option<Arc<Box<Image>>> { pub fn get_image(&mut self, node_address: NodeAddress) -> Option<Arc<Image>> {
debug!("get_image() {}", self.url.serialize()); debug!("get_image() {}", self.url.serialize());
// If this is the first time we've called this function, load // If this is the first time we've called this function, load

View file

@ -31,7 +31,7 @@ pub enum Msg {
StorePrefetchedImageData(Url, Result<Vec<u8>, ()>), StorePrefetchedImageData(Url, Result<Vec<u8>, ()>),
/// Used by the decoder tasks to post decoded images back to the cache /// Used by the decoder tasks to post decoded images back to the cache
StoreImage(Url, Option<Arc<Box<Image>>>), StoreImage(Url, Option<Arc<Image>>),
/// For testing /// For testing
WaitForStore(Sender<()>), WaitForStore(Sender<()>),
@ -42,7 +42,7 @@ pub enum Msg {
#[derive(Clone)] #[derive(Clone)]
pub enum ImageResponseMsg { pub enum ImageResponseMsg {
ImageReady(Arc<Box<Image>>), ImageReady(Arc<Image>),
ImageNotReady, ImageNotReady,
ImageFailed ImageFailed
} }

View file

@ -245,7 +245,7 @@ impl CanvasRenderingContext2D {
return Some((image_data, image_size)); return Some((image_data, image_size));
} }
fn request_image_from_cache(&self, url: Url) -> Option<Arc<Box<Image>>> { fn request_image_from_cache(&self, url: Url) -> Option<Arc<Image>> {
let canvas = self.canvas.root(); let canvas = self.canvas.root();
let window = window_from_node(canvas.r()).root(); let window = window_from_node(canvas.r()).root();
let window = window.r(); let window = window.r();