[Webkit-unassigned] [Bug 264018] New: PlainText(): avoid extra buffer allocation for empty ranges

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Oct 31 18:50:45 PDT 2023


https://bugs.webkit.org/show_bug.cgi?id=264018

            Bug ID: 264018
           Summary: PlainText(): avoid extra buffer allocation for empty
                    ranges
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: HTML Editing
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: ahmad.saleem792 at gmail.com
                CC: rniwa at webkit.org, wenson_hsieh at apple.com

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!

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20231101/12c4b92d/attachment-0001.htm>


More information about the webkit-unassigned mailing list