aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmltextareaelement.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/htmltextareaelement.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/htmltextareaelement.rs')
-rwxr-xr-xcomponents/script/dom/htmltextareaelement.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 8ee42bc2c86..e3721a78213 100755
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -56,8 +56,7 @@ pub struct HTMLTextAreaElement {
}
pub trait LayoutHTMLTextAreaElementHelpers {
- #[allow(unsafe_code)]
- unsafe fn value_for_layout(self) -> String;
+ fn value_for_layout(self) -> String;
#[allow(unsafe_code)]
unsafe fn selection_for_layout(self) -> Option<Range<usize>>;
#[allow(unsafe_code)]
@@ -67,19 +66,19 @@ pub trait LayoutHTMLTextAreaElementHelpers {
}
impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
- #[allow(unrooted_must_root)]
#[allow(unsafe_code)]
- unsafe fn value_for_layout(self) -> String {
- let text = (*self.unsafe_get())
- .textinput
- .borrow_for_layout()
- .get_content();
- if text.is_empty() {
- (*self.unsafe_get())
- .placeholder
+ fn value_for_layout(self) -> String {
+ let text = unsafe {
+ self.unsafe_get()
+ .textinput
.borrow_for_layout()
- .replace("\r\n", "\n")
- .replace("\r", "\n")
+ .get_content()
+ };
+ if text.is_empty() {
+ let placeholder = unsafe { self.unsafe_get().placeholder.borrow_for_layout() };
+ // FIXME(nox): Would be cool to not allocate a new string if the
+ // placeholder is single line, but that's an unimportant detail.
+ placeholder.replace("\r\n", "\n").replace("\r", "\n").into()
} else {
text.into()
}