Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/Node.h |
| diff --git a/third_party/WebKit/Source/core/dom/Node.h b/third_party/WebKit/Source/core/dom/Node.h |
| index c3f294d8681dada445c22b00b0cb7067f96d6572..b9092a28d48f88fe0bdc5cb9e101d321b62b3253 100644 |
| --- a/third_party/WebKit/Source/core/dom/Node.h |
| +++ b/third_party/WebKit/Source/core/dom/Node.h |
| @@ -57,6 +57,7 @@ class EventDispatchHandlingState; |
| class NodeList; |
| class NodeListsNodeData; |
| class NodeOrString; |
| +class NodeLayoutData; |
| class NodeRareData; |
| class QualifiedName; |
| class RegisteredEventListener; |
| @@ -98,21 +99,43 @@ enum class SlotChangeType { |
| kChained, |
| }; |
| -class NodeRareDataBase { |
| +class NodeLayoutData { |
| public: |
| + explicit NodeLayoutData(LayoutObject* layout_object) |
| + : layout_object_(layout_object) {} |
| LayoutObject* GetLayoutObject() const { return layout_object_; } |
| void SetLayoutObject(LayoutObject* layout_object) { |
| + DCHECK_NE(&SharedEmptyData(), this); |
| layout_object_ = layout_object; |
| } |
| + static NodeLayoutData& SharedEmptyData() { |
| + static NodeLayoutData& shared_empty_data_ = *new NodeLayoutData(nullptr); |
|
esprehn
2017/04/13 18:41:08
DEFINE_STATIC_LOCAL(NodeLayoutData, shared_empty_d
nainar
2017/04/13 20:21:03
Done.
|
| + return shared_empty_data_; |
| + } |
| + bool IsSharedEmptyData() { return this == &SharedEmptyData(); } |
| + |
| + private: |
| + LayoutObject* layout_object_; |
| +}; |
| + |
| +class NodeRareDataBase { |
| + public: |
| + NodeLayoutData* GetNodeLayoutData() const { return node_layout_data_; } |
| + void SetNodeLayoutData(NodeLayoutData* node_layout_data) { |
| + DCHECK(node_layout_data); |
| + node_layout_data_ = node_layout_data; |
| + } |
| protected: |
| - NodeRareDataBase(LayoutObject* layout_object) |
| - : layout_object_(layout_object) {} |
| + NodeRareDataBase(NodeLayoutData* node_layout_data) |
| + : node_layout_data_(node_layout_data) {} |
| + ~NodeRareDataBase() { |
| + if (node_layout_data_ && !node_layout_data_->IsSharedEmptyData()) |
| + delete node_layout_data_; |
| + } |
| protected: |
| - // LayoutObjects are fully owned by their DOM node. See LayoutObject's |
| - // LIFETIME documentation section. |
| - LayoutObject* layout_object_; |
| + NodeLayoutData* node_layout_data_; |
| }; |
| class Node; |
| @@ -568,16 +591,11 @@ class CORE_EXPORT Node : public EventTarget { |
| // Note that if a Node has a layoutObject, it's parentNode is guaranteed to |
| // have one as well. |
| LayoutObject* GetLayoutObject() const { |
| - return HasRareData() ? data_.rare_data_->GetLayoutObject() |
| - : data_.layout_object_; |
| - } |
| - void SetLayoutObject(LayoutObject* layout_object) { |
| - if (HasRareData()) |
| - data_.rare_data_->SetLayoutObject(layout_object); |
| - else |
| - data_.layout_object_ = layout_object; |
| + return HasRareData() |
| + ? data_.rare_data_->GetNodeLayoutData()->GetLayoutObject() |
| + : data_.node_layout_data_->GetLayoutObject(); |
| } |
| - |
| + void SetLayoutObject(LayoutObject*); |
| // Use these two methods with caution. |
| LayoutBox* GetLayoutBox() const; |
| LayoutBoxModelObject* GetLayoutBoxModelObject() const; |
| @@ -930,10 +948,10 @@ class CORE_EXPORT Node : public EventTarget { |
| Member<Node> next_; |
| // When a node has rare data we move the layoutObject into the rare data. |
| union DataUnion { |
| - DataUnion() : layout_object_(nullptr) {} |
| + DataUnion() : node_layout_data_(&NodeLayoutData::SharedEmptyData()) {} |
| // LayoutObjects are fully owned by their DOM node. See LayoutObject's |
| // LIFETIME documentation section. |
| - LayoutObject* layout_object_; |
| + NodeLayoutData* node_layout_data_; |
| NodeRareDataBase* rare_data_; |
| } data_; |
| }; |