Skip to content

Commit

Permalink
Reduce size of Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoISnoTarget committed Sep 10, 2024
1 parent effed75 commit 328194a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions packages/dom/src/document.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::events::{EventData, HitResult, RendererEvent};
use crate::node::{Attribute, ImageData, NodeSpecificData, TextBrush};
use crate::node::{ImageData, NodeSpecificData, TextBrush};
use crate::{ElementNodeData, Node, NodeData, TextNodeData, Viewport};
use app_units::Au;
use html5ever::{local_name, namespace_url, ns, QualName};
Expand All @@ -11,7 +11,6 @@ use selectors::{matching::QuirksMode, Element};
use slab::Slab;
use std::any::Any;
use std::collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
use std::sync::Arc;
use style::selector_parser::ServoElementSnapshot;
use style::servo::media_queries::FontMetricsProvider;
use style::servo_arc::Arc as ServoArc;
Expand Down Expand Up @@ -592,12 +591,11 @@ impl Document {
}
Resource::Image(node_id, image) => {
let node = self.get_node_mut(node_id).unwrap();
node.element_data_mut().unwrap().node_specific_data =
NodeSpecificData::Image(ImageData::new(Arc::new(image)))
node.element_data_mut().unwrap().node_specific_data = NodeSpecificData::Image(ImageData::new(image))
}
Resource::Svg(node_id, tree) => {
let node = self.get_node_mut(node_id).unwrap();
node.element_data_mut().unwrap().node_specific_data = NodeSpecificData::Svg(tree)
node.element_data_mut().unwrap().node_specific_data = NodeSpecificData::Svg(*tree)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/dom/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ static FONT_DB: OnceLock<Arc<usvg::fontdb::Database>> = OnceLock::new();

#[derive(Clone, Debug)]
pub enum Resource {
Image(usize, DynamicImage),
Svg(usize, Tree),
Image(usize, Arc<DynamicImage>),
Svg(usize, Box<Tree>),
Css(usize, DocumentStyleSheet),
}
pub(crate) struct CssHandler {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl RequestHandler<Resource> for ImageHandler {
.expect("IO errors impossible with Cursor")
.decode()
{
return Resource::Image(self.0, image);
return Resource::Image(self.0, Arc::new(image));
};
// Try parse SVG

Expand All @@ -78,7 +78,7 @@ impl RequestHandler<Resource> for ImageHandler {
};

let tree = Tree::from_data(bytes, &options).unwrap();
Resource::Svg(self.0, tree)
Resource::Svg(self.0, Box::new(tree))
}
}

Expand Down

0 comments on commit 328194a

Please sign in to comment.