Index: third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.cpp |
diff --git a/third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.cpp b/third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.cpp |
index 7217ff76fc427fa2df879061fb10b6ab6c6404ef..3ebdd3b010cd779cfe2583e5b5a52954b4065c83 100644 |
--- a/third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.cpp |
+++ b/third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.cpp |
@@ -10,27 +10,58 @@ |
namespace blink { |
+struct DepthOrderedLayoutObjectListData { |
+ // LayoutObjects sorted by depth (deepest first). This structure is only |
+ // populated at the beginning of enumerations. See ordered(). |
+ Vector<DepthOrderedLayoutObjectList::LayoutObjectWithDepth> m_orderedObjects; |
+ |
+ // Outside of layout, LayoutObjects can be added and removed as needed such |
+ // as when style was changed or destroyed. They're kept in this hashset to |
+ // keep those operations fast. |
+ HashSet<LayoutObject*> m_objects; |
+}; |
+ |
+DepthOrderedLayoutObjectList::DepthOrderedLayoutObjectList() |
+ : m_data(new DepthOrderedLayoutObjectListData) |
+{ |
+} |
+ |
+DepthOrderedLayoutObjectList::~DepthOrderedLayoutObjectList() |
+{ |
+ delete m_data; |
+} |
+ |
+int DepthOrderedLayoutObjectList::size() const |
+{ |
+ return m_data->m_objects.size(); |
+} |
+ |
+bool DepthOrderedLayoutObjectList::isEmpty() const |
+{ |
+ return m_data->m_objects.isEmpty(); |
+} |
+ |
void DepthOrderedLayoutObjectList::add(LayoutObject& object) |
{ |
ASSERT(!object.frameView()->isInPerformLayout()); |
- m_objects.add(&object); |
- m_orderedObjects.clear(); |
+ m_data->m_objects.add(&object); |
+ m_data->m_orderedObjects.clear(); |
} |
void DepthOrderedLayoutObjectList::remove(LayoutObject& object) |
{ |
- auto it = m_objects.find(&object); |
- if (it == m_objects.end()) |
+ auto it = m_data->m_objects.find(&object); |
+ if (it == m_data->m_objects.end()) |
return; |
ASSERT(!object.frameView()->isInPerformLayout()); |
- m_objects.remove(it); |
- m_orderedObjects.clear(); |
+ m_data->m_objects.remove(it); |
+ m_data->m_orderedObjects.clear(); |
} |
void DepthOrderedLayoutObjectList::clear() |
{ |
- m_objects.clear(); |
- m_orderedObjects.clear(); |
+ m_data->m_objects.clear(); |
+ m_data->m_orderedObjects.clear(); |
} |
unsigned DepthOrderedLayoutObjectList::LayoutObjectWithDepth::determineDepth(LayoutObject* object) |
@@ -41,14 +72,19 @@ unsigned DepthOrderedLayoutObjectList::LayoutObjectWithDepth::determineDepth(Lay |
return depth; |
} |
+const HashSet<LayoutObject*>& DepthOrderedLayoutObjectList::unordered() const |
+{ |
+ return m_data->m_objects; |
+} |
+ |
const Vector<DepthOrderedLayoutObjectList::LayoutObjectWithDepth>& DepthOrderedLayoutObjectList::ordered() |
{ |
- if (m_objects.isEmpty() || !m_orderedObjects.isEmpty()) |
- return m_orderedObjects; |
+ if (m_data->m_objects.isEmpty() || !m_data->m_orderedObjects.isEmpty()) |
+ return m_data->m_orderedObjects; |
- copyToVector(m_objects, m_orderedObjects); |
- std::sort(m_orderedObjects.begin(), m_orderedObjects.end()); |
- return m_orderedObjects; |
+ copyToVector(m_data->m_objects, m_data->m_orderedObjects); |
+ std::sort(m_data->m_orderedObjects.begin(), m_data->m_orderedObjects.end()); |
+ return m_data->m_orderedObjects; |
} |
} // namespace blink |