script: Modify and copy the contents of <textarea> placeholder less#43452
Merged
mrobinson merged 1 commit intoservo:mainfrom Mar 19, 2026
Merged
script: Modify and copy the contents of <textarea> placeholder less#43452mrobinson merged 1 commit intoservo:mainfrom
<textarea> placeholder less#43452mrobinson merged 1 commit intoservo:mainfrom
Conversation
simonwuelker
requested changes
Mar 19, 2026
|
|
||
| pub fn clear(&mut self) { | ||
| *self.0.borrow_mut() = DOMStringType::Rust(String::new()) | ||
| self.ensure_rust_string().clear() |
Member
There was a problem hiding this comment.
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
Member
Author
There was a problem hiding this comment.
Excellent point. I've addressed this.
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>
e332798 to
3a88f05
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theplaceholder and viceversa).
In addition make it so that
DOMString::clearpreserves the stringallocation when called.
Testing: This is just a small optimization so testing should not be necessary. Existing behavior is verified via WPT tests.