Commit d198d959 authored by sigbjornf's avatar sigbjornf Committed by Commit bot

Clean up markClientsAndObserversFinished().

Simplify transferring a counted element entry from one set to another.

To do so, add generalized version of add() over HashCountedSet that lets
the caller specify a count.

R=
BUG=

Review-Url: https://codereview.chromium.org/2045883002
Cr-Commit-Position: refs/heads/master@{#398275}
parent 22d7c9d0
...@@ -106,13 +106,10 @@ void ImageResource::checkNotify() ...@@ -106,13 +106,10 @@ void ImageResource::checkNotify()
void ImageResource::markClientsAndObserversFinished() void ImageResource::markClientsAndObserversFinished()
{ {
while (!m_observers.isEmpty()) { HashCountedSet<ImageResourceObserver*> observers;
HashCountedSet<ImageResourceObserver*>::iterator it = m_observers.begin(); m_observers.swap(observers);
for (int i = it->value; i; i--) { for (const auto& it : observers)
m_finishedObservers.add(it->key); m_finishedObservers.add(it.key, it.value);
m_observers.remove(it);
}
}
Resource::markClientsAndObserversFinished(); Resource::markClientsAndObserversFinished();
} }
......
...@@ -394,13 +394,10 @@ void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy) ...@@ -394,13 +394,10 @@ void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy)
void Resource::markClientsAndObserversFinished() void Resource::markClientsAndObserversFinished()
{ {
while (!m_clients.isEmpty()) { HashCountedSet<ResourceClient*> clients;
HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); m_clients.swap(clients);
for (int i = it->value; i; i--) { for (const auto& it : clients)
m_finishedClients.add(it->key); m_finishedClients.add(it.key, it.value);
m_clients.remove(it);
}
}
} }
void Resource::error(const ResourceError& error) void Resource::error(const ResourceError& error)
......
...@@ -45,7 +45,7 @@ static WidgetToParentMap& widgetNewParentMap() ...@@ -45,7 +45,7 @@ static WidgetToParentMap& widgetNewParentMap()
return map; return map;
} }
typedef HeapHashSet<Member<Widget>> WidgetSet; using WidgetSet = HeapHashSet<Member<Widget>>;
static WidgetSet& widgetsPendingTemporaryRemovalFromParent() static WidgetSet& widgetsPendingTemporaryRemovalFromParent()
{ {
// Widgets in this set will not leak because it will be cleared in // Widgets in this set will not leak because it will be cleared in
...@@ -54,9 +54,9 @@ static WidgetSet& widgetsPendingTemporaryRemovalFromParent() ...@@ -54,9 +54,9 @@ static WidgetSet& widgetsPendingTemporaryRemovalFromParent()
return set; return set;
} }
HeapHashCountedSet<Member<Node>>& SubframeLoadingDisabler::disabledSubtreeRoots() SubframeLoadingDisabler::SubtreeRootSet& SubframeLoadingDisabler::disabledSubtreeRoots()
{ {
DEFINE_STATIC_LOCAL(HeapHashCountedSet<Member<Node>>, nodes, (new HeapHashCountedSet<Member<Node>>)); DEFINE_STATIC_LOCAL(SubtreeRootSet, nodes, (new SubtreeRootSet));
return nodes; return nodes;
} }
......
...@@ -140,7 +140,9 @@ public: ...@@ -140,7 +140,9 @@ public:
} }
private: private:
CORE_EXPORT static HeapHashCountedSet<Member<Node>>& disabledSubtreeRoots(); using SubtreeRootSet = HeapHashCountedSet<Member<Node>>;
CORE_EXPORT static SubtreeRootSet& disabledSubtreeRoots();
Member<Node> m_root; Member<Node> m_root;
}; };
......
...@@ -71,6 +71,9 @@ public: ...@@ -71,6 +71,9 @@ public:
// true if an new entry was added. // true if an new entry was added.
AddResult add(const ValueType&); AddResult add(const ValueType&);
// Generalized add(), adding the value N times.
AddResult add(const ValueType&, unsigned);
// Reduces the count of the value, and removes it if count goes down to // Reduces the count of the value, and removes it if count goes down to
// zero, returns true if the value is removed. // zero, returns true if the value is removed.
bool remove(const ValueType& value) { return remove(find(value)); } bool remove(const ValueType& value) { return remove(find(value)); }
...@@ -91,13 +94,20 @@ private: ...@@ -91,13 +94,20 @@ private:
}; };
template <typename T, typename U, typename V, typename W> template <typename T, typename U, typename V, typename W>
inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W>::add(const ValueType& value) inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W>::add(const ValueType& value, unsigned count)
{ {
DCHECK_GT(count, 0u);
AddResult result = m_impl.add(value, 0); AddResult result = m_impl.add(value, 0);
++result.storedValue->value; result.storedValue->value += count;
return result; return result;
} }
template <typename T, typename U, typename V, typename W>
inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W>::add(const ValueType& value)
{
return add(value, 1u);
}
template <typename T, typename U, typename V, typename W> template <typename T, typename U, typename V, typename W>
inline bool HashCountedSet<T, U, V, W>::remove(iterator it) inline bool HashCountedSet<T, U, V, W>::remove(iterator it)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment