aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_thread_2020/dom_wrapper.rs
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2020-03-31 10:51:18 -0400
committerGitHub <noreply@github.com>2020-03-31 10:51:18 -0400
commit3aa15e3fa30194e465c8bbb21c07d5239a6ac9f8 (patch)
treebd64feee4c1f3d5861f5714b032dd3a52fd2aa70 /components/layout_thread_2020/dom_wrapper.rs
parent09271826f6a771cace1755dd18794d7085fccbd3 (diff)
parentfb1ff3f097c0c8a994c9e7c4bb72c3ba5b64492d (diff)
downloadservo-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_2020/dom_wrapper.rs')
-rw-r--r--components/layout_thread_2020/dom_wrapper.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/components/layout_thread_2020/dom_wrapper.rs b/components/layout_thread_2020/dom_wrapper.rs
index d8aa7b05360..7d57d7f511e 100644
--- a/components/layout_thread_2020/dom_wrapper.rs
+++ b/components/layout_thread_2020/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};
@@ -835,7 +836,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,
@@ -1117,9 +1118,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>> {