Skip to content

Commit

Permalink
Free up a bit in Node::TypeFlag
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267015

Reviewed by Tim Nguyen.

This PR frees up 1 bit in Node::TypeFlag by consolidating TypeFlag::IsEditingText and
TypeFlag::IsDocumentFragmentForInnerOuterHTML into a single flag: TypeFlag::IsSpecialInternalNode.

* Source/WebCore/dom/DocumentFragment.cpp:
(WebCore::DocumentFragment::createForInnerOuterHTML):
* Source/WebCore/dom/Node.h:
(WebCore::Node::isEditingText const):
(WebCore::Node::isDocumentFragmentForInnerOuterHTML const):
* Source/WebCore/dom/Text.cpp:
(WebCore::Text::createEditingText):

Canonical link: https://commits.webkit.org/272597@main
  • Loading branch information
rniwa committed Jan 3, 2024
1 parent 668a334 commit af16a58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Source/WebCore/dom/DocumentFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ Ref<DocumentFragment> DocumentFragment::create(Document& document)

Ref<DocumentFragment> DocumentFragment::createForInnerOuterHTML(Document& document)
{
return adoptRef(*new DocumentFragment(document, TypeFlag::IsDocumentFragmentForInnerOuterHTML));
auto node = adoptRef(*new DocumentFragment(document, TypeFlag::IsSpecialInternalNode));
ASSERT(node->isDocumentFragmentForInnerOuterHTML());
return node;
}

String DocumentFragment::nodeName() const
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/dom/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ class Node : public EventTarget, public CanMakeCheckedPtr {
bool hasInvalidRenderer() const { return hasStyleFlag(NodeStyleFlag::HasInvalidRenderer); }
bool styleResolutionShouldRecompositeLayer() const { return hasStyleFlag(NodeStyleFlag::StyleResolutionShouldRecompositeLayer); }
bool childNeedsStyleRecalc() const { return hasStyleFlag(NodeStyleFlag::DescendantNeedsStyleResolution); }
bool isEditingText() const { return hasTypeFlag(TypeFlag::IsEditingText); }
bool isEditingText() const { return isTextNode() && hasTypeFlag(TypeFlag::IsSpecialInternalNode); }

bool isDocumentFragmentForInnerOuterHTML() const { return hasTypeFlag(TypeFlag::IsDocumentFragmentForInnerOuterHTML); }
bool isDocumentFragmentForInnerOuterHTML() const { return isDocumentFragment() && hasTypeFlag(TypeFlag::IsSpecialInternalNode); }

void setChildNeedsStyleRecalc() { setStyleFlag(NodeStyleFlag::DescendantNeedsStyleResolution); }
void clearChildNeedsStyleRecalc();
Expand Down Expand Up @@ -586,9 +586,9 @@ class Node : public EventTarget, public CanMakeCheckedPtr {
IsMathMLElement = 1 << 6,
IsShadowRoot = 1 << 7,
IsUnknownElement = 1 << 8,
IsDocumentFragmentForInnerOuterHTML = 1 << 9,
IsEditingText = 1 << 10,
HasCustomStyleResolveCallbacks = 1 << 11,
IsSpecialInternalNode = 1 << 9, // DocumentFragment node for innerHTML/outerHTML or EditingText node.
HasCustomStyleResolveCallbacks = 1 << 10,
// 1 free bit.
};
static constexpr auto typeFlagBitCount = 12;

Expand Down
4 changes: 3 additions & 1 deletion Source/WebCore/dom/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ Ref<Text> Text::create(Document& document, String&& data)

Ref<Text> Text::createEditingText(Document& document, String&& data)
{
return adoptRef(*new Text(document, WTFMove(data), TEXT_NODE, { TypeFlag::IsEditingText }));
auto node = adoptRef(*new Text(document, WTFMove(data), TEXT_NODE, { TypeFlag::IsSpecialInternalNode }));
ASSERT(node->isEditingText());
return node;
}

Text::~Text() = default;
Expand Down

0 comments on commit af16a58

Please sign in to comment.