aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/node.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/script/dom/node.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/script/dom/node.rs')
-rw-r--r--components/script/dom/node.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index d92e3b6a364..251f6fcab18 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -87,7 +87,7 @@ use servo_arc::Arc;
use servo_atoms::Atom;
use servo_url::ServoUrl;
use smallvec::SmallVec;
-use std::borrow::ToOwned;
+use std::borrow::Cow;
use std::cell::{Cell, UnsafeCell};
use std::cmp;
use std::default::Default;
@@ -1326,7 +1326,7 @@ pub trait LayoutNodeHelpers<'dom> {
unsafe fn init_style_and_layout_data(self, _: OpaqueStyleAndLayoutData);
unsafe fn take_style_and_layout_data(self) -> OpaqueStyleAndLayoutData;
- fn text_content(self) -> String;
+ fn text_content(self) -> Cow<'dom, str>;
fn selection(self) -> Option<Range<usize>>;
fn image_url(self) -> Option<ServoUrl>;
fn image_density(self) -> Option<f64>;
@@ -1456,18 +1456,17 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
val
}
- #[allow(unsafe_code)]
- fn text_content(self) -> String {
+ fn text_content(self) -> Cow<'dom, str> {
if let Some(text) = self.downcast::<Text>() {
- return unsafe { text.upcast().data_for_layout().to_owned() };
+ return text.upcast().data_for_layout().into();
}
if let Some(input) = self.downcast::<HTMLInputElement>() {
- return unsafe { input.value_for_layout() };
+ return input.value_for_layout();
}
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
- return unsafe { area.value_for_layout() };
+ return area.value_for_layout().into();
}
panic!("not text!")