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()
void ImageResource::markClientsAndObserversFinished()
{
while (!m_observers.isEmpty()) {
HashCountedSet<ImageResourceObserver*>::iterator it = m_observers.begin();
for (int i = it->value; i; i--) {
m_finishedObservers.add(it->key);
m_observers.remove(it);
}
}
HashCountedSet<ImageResourceObserver*> observers;
m_observers.swap(observers);
for (const auto& it : observers)
m_finishedObservers.add(it.key, it.value);
Resource::markClientsAndObserversFinished();
}
......
......@@ -394,13 +394,10 @@ void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy)
void Resource::markClientsAndObserversFinished()
{
while (!m_clients.isEmpty()) {
HashCountedSet<ResourceClient*>::iterator it = m_clients.begin();
for (int i = it->value; i; i--) {
m_finishedClients.add(it->key);
m_clients.remove(it);
}
}
HashCountedSet<ResourceClient*> clients;
m_clients.swap(clients);
for (const auto& it : clients)
m_finishedClients.add(it.key, it.value);
}
void Resource::error(const ResourceError& error)
......
......@@ -45,7 +45,7 @@ static WidgetToParentMap& widgetNewParentMap()
return map;
}
typedef HeapHashSet<Member<Widget>> WidgetSet;
using WidgetSet = HeapHashSet<Member<Widget>>;
static WidgetSet& widgetsPendingTemporaryRemovalFromParent()
{
// Widgets in this set will not leak because it will be cleared in
......@@ -54,9 +54,9 @@ static WidgetSet& widgetsPendingTemporaryRemovalFromParent()
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;
}
......
......@@ -140,7 +140,9 @@ public:
}
private:
CORE_EXPORT static HeapHashCountedSet<Member<Node>>& disabledSubtreeRoots();
using SubtreeRootSet = HeapHashCountedSet<Member<Node>>;
CORE_EXPORT static SubtreeRootSet& disabledSubtreeRoots();
Member<Node> m_root;
};
......
......@@ -71,6 +71,9 @@ public:
// true if an new entry was added.
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
// zero, returns true if the value is removed.
bool remove(const ValueType& value) { return remove(find(value)); }
......@@ -91,13 +94,20 @@ private:
};
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);
++result.storedValue->value;
result.storedValue->value += count;
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>
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