diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-03-31 10:51:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 10:51:18 -0400 |
commit | 3aa15e3fa30194e465c8bbb21c07d5239a6ac9f8 (patch) | |
tree | bd64feee4c1f3d5861f5714b032dd3a52fd2aa70 /components/layout_2020/dom_traversal.rs | |
parent | 09271826f6a771cace1755dd18794d7085fccbd3 (diff) | |
parent | fb1ff3f097c0c8a994c9e7c4bb72c3ba5b64492d (diff) | |
download | servo-3aa15e3fa30194e465c8bbb21c07d5239a6ac9f8.tar.gz servo-3aa15e3fa30194e465c8bbb21c07d5239a6ac9f8.zip |
Auto merge of #26070 - servo:layout-2020-more-cleanups, r=SimonSapin
Make LayoutNodeHelpers::text_content return a cow
What does it mean? It means that layout can process `Text` nodes' contents by just borrowing them, potentially saving us from a lot of unnecessary tempoorary allocations, which is nice.
Diffstat (limited to 'components/layout_2020/dom_traversal.rs')
-rw-r--r-- | components/layout_2020/dom_traversal.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/components/layout_2020/dom_traversal.rs b/components/layout_2020/dom_traversal.rs index 020282f50ff..ef4570a85bb 100644 --- a/components/layout_2020/dom_traversal.rs +++ b/components/layout_2020/dom_traversal.rs @@ -17,6 +17,7 @@ use script_layout_interface::wrapper_traits::{ }; use script_layout_interface::HTMLCanvasDataSource; use servo_arc::Arc as ServoArc; +use std::borrow::Cow; use std::marker::PhantomData as marker; use std::sync::{Arc, Mutex}; use style::dom::{OpaqueNode, TNode}; @@ -59,7 +60,12 @@ pub(super) trait TraversalHandler<'dom, Node> where Node: 'dom, { - fn handle_text(&mut self, node: Node, text: String, parent_style: &ServoArc<ComputedValues>); + fn handle_text( + &mut self, + node: Node, + text: Cow<'dom, str>, + parent_style: &ServoArc<ComputedValues>, + ); /// Or pseudo-element fn handle_element( @@ -166,7 +172,7 @@ fn traverse_pseudo_element_contents<'dom, Node>( for item in items { match item { PseudoElementContentItem::Text(text) => { - handler.handle_text(node, text, pseudo_element_style) + handler.handle_text(node, text.into(), pseudo_element_style) }, PseudoElementContentItem::Replaced(contents) => { let item_style = anonymous_style.get_or_insert_with(|| { @@ -351,7 +357,7 @@ impl Drop for BoxSlot<'_> { pub(crate) trait NodeExt<'dom>: 'dom + Copy + LayoutNode<'dom> + Send + Sync { fn is_element(self) -> bool; - fn as_text(self) -> Option<String>; + fn as_text(self) -> Option<Cow<'dom, str>>; /// Returns the image if it’s loaded, and its size in image pixels /// adjusted for `image_density`. @@ -378,7 +384,7 @@ where self.to_threadsafe().as_element().is_some() } - fn as_text(self) -> Option<String> { + fn as_text(self) -> Option<Cow<'dom, str>> { if self.is_text_node() { Some(self.to_threadsafe().node_text_content()) } else { |