Skip to content

script: Modify and copy the contents of <textarea> placeholder less#43452

Merged
mrobinson merged 1 commit intoservo:mainfrom
mrobinson:do-less-copying-of-placeholder
Mar 19, 2026
Merged

script: Modify and copy the contents of <textarea> placeholder less#43452
mrobinson merged 1 commit intoservo:mainfrom
mrobinson:do-less-copying-of-placeholder

Conversation

@mrobinson
Copy link
Copy Markdown
Member

Instead of always doing the newline fixup on the <textarea>
placeholder, only do it when the placeholder attribute itself changes.
This avoids doing string replacements when they are not necessary (such
as when a <textarea> switches from having text to only having the
placeholder and viceversa).

In addition make it so that DOMString::clear preserves the string
allocation when called.

Testing: This is just a small optimization so testing should not be necessary. Existing behavior is verified via WPT tests.

@mrobinson mrobinson requested a review from gterzian as a code owner March 19, 2026 09:06
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 19, 2026
Comment thread components/script_bindings/domstring.rs Outdated

pub fn clear(&mut self) {
*self.0.borrow_mut() = DOMStringType::Rust(String::new())
self.ensure_rust_string().clear()
Copy link
Copy Markdown
Member

@simonwuelker simonwuelker Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no point in doing a potentially expensive conversion to a rust string only to then immediately throw the result away.

In addition make it so that DOMString::clear preserves the string
allocation when called.

We should only do this if the string is already a rust string, otherwise the capacity we preserve is the one we just allocated in ensure_rust_string

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point. I've addressed this.

@servo-highfive servo-highfive added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 19, 2026
Instead of always doing the newline fixup on the `<textarea>`
placeholder, only do it when the placeholder attribute itself changes.
This avoids doing string replacements when they are not necessary (such
as when a `<textarea>` switches from having text to only having the
placeholder and viceversa).

In addition make it so that `DOMString::clear` preserves the string
allocation when called.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
@mrobinson mrobinson force-pushed the do-less-copying-of-placeholder branch from e332798 to 3a88f05 Compare March 19, 2026 15:49
@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 19, 2026
Copy link
Copy Markdown
Member

@simonwuelker simonwuelker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Mar 19, 2026
@mrobinson mrobinson enabled auto-merge March 19, 2026 15:54
@mrobinson mrobinson added this pull request to the merge queue Mar 19, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Mar 19, 2026
Merged via the queue into servo:main with commit 56e7945 Mar 19, 2026
33 checks passed
@mrobinson mrobinson deleted the do-less-copying-of-placeholder branch March 19, 2026 16:41
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Mar 19, 2026
Gae24 pushed a commit to Gae24/servo that referenced this pull request Mar 26, 2026
…servo#43452)

Instead of always doing the newline fixup on the `<textarea>`
placeholder, only do it when the placeholder attribute itself changes.
This avoids doing string replacements when they are not necessary (such
as when a `<textarea>` switches from having text to only having the
placeholder and viceversa).

In addition make it so that `DOMString::clear` preserves the string
allocation when called.

Testing: This is just a small optimization so testing should not be
necessary. Existing behavior is verified via WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants