Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Move some of the work from Element::insertedIntoAncestor() / removedF…
…romAncestor() to subclasses https://bugs.webkit.org/show_bug.cgi?id=240914 Reviewed by Ryosuke Niwa and Darin Adler. Move some of the work from Element::insertedIntoAncestor() / removedFromAncestor() to subclasses. These functions are hot and should be kept as efficient as possible. There is no reason for every Element to pay run-time cost for checks that only apply to article or label elements. * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/Element.cpp: (WebCore::Element::insertedIntoAncestor): (WebCore::Element::removedFromAncestor): * Source/WebCore/dom/Element.h: * Source/WebCore/html/HTMLArticleElement.cpp: Added. (WebCore::HTMLArticleElement::create): (WebCore::HTMLArticleElement::HTMLArticleElement): (WebCore::HTMLArticleElement::insertedIntoAncestor): (WebCore::HTMLArticleElement::removedFromAncestor): * Source/WebCore/html/HTMLArticleElement.h: Added. * Source/WebCore/html/HTMLLabelElement.cpp: (WebCore::HTMLLabelElement::insertedIntoAncestor): (WebCore::HTMLLabelElement::removedFromAncestor): * Source/WebCore/html/HTMLLabelElement.h: * Source/WebCore/html/HTMLTagNames.in: Canonical link: https://commits.webkit.org/251041@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294930 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
10 changed files
with
153 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "HTMLArticleElement.h" | ||
|
||
#include "HTMLDocument.h" | ||
#include "HTMLNames.h" | ||
#include <wtf/IsoMallocInlines.h> | ||
|
||
namespace WebCore { | ||
|
||
WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLArticleElement); | ||
|
||
Ref<HTMLArticleElement> HTMLArticleElement::create(const QualifiedName& tagName, Document& document) | ||
{ | ||
return adoptRef(*new HTMLArticleElement(tagName, document)); | ||
} | ||
|
||
HTMLArticleElement::HTMLArticleElement(const QualifiedName& tagName, Document& document) | ||
: HTMLElement(tagName, document) | ||
{ | ||
ASSERT(tagName == HTMLNames::articleTag); | ||
} | ||
|
||
auto HTMLArticleElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree) -> InsertedIntoAncestorResult | ||
{ | ||
auto result = HTMLElement::insertedIntoAncestor(insertionType, parentOfInsertedTree); | ||
|
||
if (insertionType.connectedToDocument) { | ||
if (auto* newDocument = dynamicDowncast<HTMLDocument>(parentOfInsertedTree.document())) | ||
newDocument->registerArticleElement(*this); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
void HTMLArticleElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree) | ||
{ | ||
if (removalType.disconnectedFromDocument) | ||
oldParentOfRemovedTree.document().unregisterArticleElement(*this); | ||
|
||
HTMLElement::removedFromAncestor(removalType, oldParentOfRemovedTree); | ||
} | ||
|
||
} // namespace WebCore |
This file contains 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
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "HTMLElement.h" | ||
|
||
namespace WebCore { | ||
|
||
class HTMLArticleElement final : public HTMLElement { | ||
WTF_MAKE_ISO_ALLOCATED(HTMLArticleElement); | ||
public: | ||
static Ref<HTMLArticleElement> create(const QualifiedName&, Document&); | ||
|
||
private: | ||
InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) final; | ||
void removedFromAncestor(RemovalType, ContainerNode& oldParentOfRemovedTree) final; | ||
|
||
HTMLArticleElement(const QualifiedName&, Document&); | ||
}; | ||
|
||
} // namespace WebCore |
This file contains 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
This file contains 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
This file contains 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