Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 5824bab256ea74d26c8d4375ac7dbcabfc5c137d
      
https://github.com/WebKit/WebKit/commit/5824bab256ea74d26c8d4375ac7dbcabfc5c137d
  Author: Chris Dumez <[email protected]>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp
    M Source/WebCore/html/parser/HTMLDocumentParserFastPath.h

  Log Message:
  -----------
  Avoid allocating a new DocumentFragment when tryFastParsingHTMLFragment() 
fails
https://bugs.webkit.org/show_bug.cgi?id=252453

Reviewed by Ryosuke Niwa.

We have an optimization in place in createFragmentForMarkup() to keep reusing
the same DocumentFragment (Document::documentFragmentForInnerOuterHTML())
whenever the innerHTML setter is called. documentFragmentForInnerOuterHTML()
calls removeChildren() on the DocumentFragment in between calls for reuse.

We recently added a new fast HTML parsing path for innerHTML. However, when
fast parsing fails, it may leave the DocumentFragment with children due to
partial parsing. To address this, we were re-constructing the
DocumentFragment before calling the full HTML parser (slow path).

In this patch, we now call removeChildren() on the DocumentFragment if the
fast path fails, instead of re-allocating a new DocumentFragment. This is
consistent with what documentFragmentForInnerOuterHTML() is doing and
maintains our optimization which avoids re-allocating new DocumentFragments
for each innerHTML assignment.

* Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp:
(WebCore::tryFastParsingHTMLFragmentImpl):
(WebCore::tryFastParsingHTMLFragment):
* Source/WebCore/html/parser/HTMLDocumentParserFastPath.h:

Canonical link: https://commits.webkit.org/260424@main


_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to