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_thread/dom_wrapper.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_thread/dom_wrapper.rs')
-rw-r--r-- | components/layout_thread/dom_wrapper.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index f2ba0a6fafa..e3197c8e78a 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -67,6 +67,7 @@ use selectors::sink::Push; use servo_arc::{Arc, ArcBorrow}; use servo_atoms::Atom; use servo_url::ServoUrl; +use std::borrow::Cow; use std::fmt; use std::fmt::Debug; use std::hash::{Hash, Hasher}; @@ -828,7 +829,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { .dom_children() .all(|node| match node.script_type_id() { NodeTypeId::Element(..) => false, - NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => unsafe { + NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => { node.node.downcast().unwrap().data_for_layout().is_empty() }, _ => true, @@ -1110,9 +1111,8 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> { self.node } - fn node_text_content(&self) -> String { - let this = unsafe { self.get_jsmanaged() }; - return this.text_content(); + fn node_text_content(self) -> Cow<'ln, str> { + unsafe { self.get_jsmanaged().text_content() } } fn selection(&self) -> Option<Range<ByteIndex>> { |