Skip to content

Commit

Permalink
Move data members specific to ElementRareData out of NodeRareData
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=253461

Reviewed by Darin Adler.

Move data members specific to ElementRareData out of NodeRareData. Those were
put in NodeRareData for better packing but we can achieve the same packing by
reordering data members.

I have verified that sizeof(NodeRareData)=32 and sizeof(ElementRareDate)=232
before and after my change.

* Source/WebCore/dom/ElementRareData.cpp:
* Source/WebCore/dom/ElementRareData.h:
(WebCore::ElementRareData::useTypes const):
* Source/WebCore/dom/NodeRareData.cpp:
* Source/WebCore/dom/NodeRareData.h:
(WebCore::NodeRareData::isElementRareData const):
(WebCore::NodeRareData::useTypes const):
(WebCore::NodeRareData::isElementRareData): Deleted.

Canonical link: https://commits.webkit.org/261308@main
  • Loading branch information
cdumez committed Mar 7, 2023
1 parent 68217ea commit 11ece51
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Source/WebCore/dom/ElementRareData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
namespace WebCore {

struct SameSizeAsElementRareData : NodeRareData {
unsigned short m_childIndex;
int m_tabIndex;
IntPoint savedLayerScrollPosition;
Vector<std::unique_ptr<ElementAnimationRareData>> animationRareData;
void* pointers[16];
Expand Down
7 changes: 5 additions & 2 deletions Source/WebCore/dom/ElementRareData.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,16 @@ class ElementRareData : public NodeRareData {
result.add(UseType::ExplicitlySetAttrElementsMap);
if (m_popoverData)
result.add(UseType::Popover);
if (m_childIndex)
result.add(UseType::ChildIndex);
return result;
}
#endif

private:
unsigned short m_childIndex { 0 }; // Keep on top for better bit packing with NodeRareData.
int m_unusualTabIndex { 0 }; // Keep on top for better bit packing with NodeRareData.

IntPoint m_savedLayerScrollPosition;
std::unique_ptr<RenderStyle> m_computedStyle;
std::unique_ptr<RenderStyle> m_displayContentsStyle;
Expand Down Expand Up @@ -234,8 +239,6 @@ class ElementRareData : public NodeRareData {
ExplicitlySetAttrElementsMap m_explicitlySetAttrElementsMap;

std::unique_ptr<PopoverData> m_popoverData;

void releasePseudoElement(PseudoElement*);
};

inline ElementRareData::ElementRareData()
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/dom/NodeRareData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
namespace WebCore {

struct SameSizeAsNodeRareData {
uint32_t m_tabIndex;
uint32_t m_childIndexAndIsElementRareDataFlag;
void* m_pointer[2];
WeakPtr<Node, WeakPtrImplWithEventTargetData> m_weakPointer;
bool m_isElementRareData;
};

static_assert(sizeof(NodeRareData) == sizeof(SameSizeAsNodeRareData), "NodeRareData should stay small");
Expand Down
12 changes: 2 additions & 10 deletions Source/WebCore/dom/NodeRareData.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class NodeRareData {
{
}

bool isElementRareData() { return m_isElementRareData; }
bool isElementRareData() const { return m_isElementRareData; }

void clearNodeLists() { m_nodeLists = nullptr; }
NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
Expand Down Expand Up @@ -292,8 +292,6 @@ class NodeRareData {
OptionSet<UseType> result;
if (m_unusualTabIndex)
result.add(UseType::TabIndex);
if (m_childIndex)
result.add(UseType::ChildIndex);
if (m_nodeLists)
result.add(UseType::NodeList);
if (m_mutationObserverData)
Expand All @@ -306,17 +304,11 @@ class NodeRareData {

void operator delete(NodeRareData*, std::destroying_delete_t);

protected:
// Used by ElementRareData. Defined here for better packing in 64-bit.
int m_unusualTabIndex { 0 };
unsigned short m_childIndex { 0 };

private:
bool m_isElementRareData;

std::unique_ptr<NodeListsNodeData> m_nodeLists;
std::unique_ptr<NodeMutationObserverData> m_mutationObserverData;
WeakPtr<HTMLSlotElement, WeakPtrImplWithEventTargetData> m_manuallyAssignedSlot;
bool m_isElementRareData; // Keep last for better bit packing with ElementRareData.
};

template<> struct NodeListTypeIdentifier<NameNodeList> {
Expand Down

0 comments on commit 11ece51

Please sign in to comment.