[webkit-changes] [WebKit/WebKit] 9179c8: Optimize FormListedElement::resetFormOwner()

Chris Dumez noreply at github.com
Sun Mar 19 15:20:51 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9179c86d6cece98d4063152919f5f380f3c56aa5
      https://github.com/WebKit/WebKit/commit/9179c86d6cece98d4063152919f5f380f3c56aa5
  Author: Chris Dumez <cdumez at apple.com>
  Date:   2023-03-19 (Sun, 19 Mar 2023)

  Changed paths:
    M Source/WebCore/html/FormAssociatedElement.cpp
    M Source/WebCore/html/FormAssociatedElement.h
    M Source/WebCore/html/FormListedElement.cpp
    M Source/WebCore/html/FormListedElement.h
    M Source/WebCore/html/HTMLImageElement.cpp
    M Source/WebCore/html/HTMLImageElement.h

  Log Message:
  -----------
  Optimize FormListedElement::resetFormOwner()
https://bugs.webkit.org/show_bug.cgi?id=254104

Reviewed by Darin Adler.

Optimize FormListedElement::resetFormOwner():
- Update findAssociatedForm() to only get the form attribute if the element is
  connected. Looking up an attribute is a linear search and this is often
  called for disconnected elements.
- setForm() was marked as virtual but never actually overriden. Drop the
  virtual. Also inline it so that we can avoid a function call if the new
  form is the same as the existing one. The slow path is a virtual function
  call to setFormInternal().

Also made a few drive-by cleanups:
- Update findAssociatedForm() to take the element by reference instead of a raw
  pointer since it cannot be null.
- Make findAssociatedForm() private since it is never called from outside the
  class.
- Use a bit more smart pointers for extra safety.

* Source/WebCore/html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::setFormInternal):
(WebCore::FormAssociatedElement::setForm): Deleted.
* Source/WebCore/html/FormAssociatedElement.h:
(WebCore::FormAssociatedElement::setForm):
* Source/WebCore/html/FormListedElement.cpp:
(WebCore::findAssociatedForm):
(WebCore::FormListedElement::setFormInternal):
(WebCore::FormListedElement::resetFormOwner):
(WebCore::FormListedElement::findAssociatedForm): Deleted.
* Source/WebCore/html/FormListedElement.h:
* Source/WebCore/html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::setFormInternal):
* Source/WebCore/html/HTMLImageElement.h:

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




More information about the webkit-changes mailing list