Bug 264018
| Summary: | PlainText(): avoid extra buffer allocation for empty ranges | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ahmad Saleem <ahmad.saleem792> |
| Component: | HTML Editing | Assignee: | Ahmad Saleem <ahmad.saleem792> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | fantasai.bugs, karlcow, rniwa, webkit-bug-importer, wenson_hsieh |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Ahmad Saleem
Hi team,
Came across potential improvement from Blink's Commit:
Commit: https://chromium.googlesource.com/chromium/blink/+/0b34a706cb547c672215c108270ffb8d344fb097
WebKit Source: https://searchfox.org/wubkat/source/Source/WebCore/editing/TextIterator.cpp#2531
___
This compiles:
String plainText(const SimpleRange& range, TextIteratorBehaviors defaultBehavior, bool isDisplayString)
{
TextIterator it(range, defaultBehavior);
if (it.atEnd())
return emptyString();
// The initial buffer size can be critical for performance: https://bugs.webkit.org/show_bug.cgi?id=81192
constexpr unsigned initialCapacity = 1 << 15;
Ref document = range.start.document();
StringBuilder builder;
builder.reserveCapacity(initialCapacity);
TextIteratorBehaviors behaviors = defaultBehavior;
if (!isDisplayString)
behaviors.add(TextIteratorBehavior::EmitsTextsWithoutTranscoding);
for (; !it.atEnd(); it.advance())
it.appendTextToStringBuilder(builder);
if (builder.isEmpty())
return emptyString();
String result = builder.toString();
...
___
Just wanted to raise to get input, whether it is worthwhile to add. I didn't run any test suite to confirm whether it regress anything or not.
Thanks!
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Ahmad Saleem
PR Attempt: https://github.com/WebKit/WebKit/pull/19831
NOTE - It leads to 'backslash to Yen' hack being disabled and leading to expectation changes in few of test cases:
editing/execCommand/transpose-backslash-with-euc.html
fast/encoding/yentest.html
fast/encoding/yentest2.html
imported/w3c/web-platform-tests/html/semantics/forms/the-option-element/option-text-backslash.html
editing/pasteboard/copy-backslash-with-euc.html
editing/execCommand/transpose-backslash-with-euc.html
___
I don't know whether we have any plans to remove 'backslash to yen' yet but it is removed by Blink.
Just wanted to document here, all these bits.
Radar WebKit Bug Importer
<rdar://problem/118090616>
Karl Dubost
Maybe Elika can give an opinion here.
Ahmad Saleem
Pull request: https://github.com/WebKit/WebKit/pull/55964
EWS
Committed 305025@main (7941ccc6aed7): <https://commits.webkit.org/305025@main>
Reviewed commits have been landed. Closing PR #55964 and removing active labels.