Commit 041b103a authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

Replace HeapListHashSet with HeapHashMap

This is part of an ongoing effort to simplify heap collections
and limit the types they can support (specifically, this CL
removes the only existing non-member usage of HeapListHashSet).

Bug: 1047147
Change-Id: I1c5de9f3a97588c22946eed03048159fd720b502
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2024896Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736884}
parent 3a45f157
...@@ -38,8 +38,24 @@ ...@@ -38,8 +38,24 @@
namespace blink { namespace blink {
std::pair<EventTarget*, StringImpl*> EventTargetKey(const Event* event) { bool ScriptedAnimationController::InsertToPerFrameEventsMap(
return std::make_pair(event->target(), event->type().Impl()); const Event* event) {
HashSet<const StringImpl*>& set =
per_frame_events_.insert(event->target(), HashSet<const StringImpl*>())
.stored_value->value;
return set.insert(event->type().Impl()).is_new_entry;
}
void ScriptedAnimationController::EraseFromPerFrameEventsMap(
const Event* event) {
EventTarget* target = event->target();
PerFrameEventsMap::iterator it = per_frame_events_.find(target);
if (it != per_frame_events_.end()) {
HashSet<const StringImpl*>& set = it->value;
set.erase(event->type().Impl());
if (set.IsEmpty())
per_frame_events_.erase(target);
}
} }
ScriptedAnimationController::ScriptedAnimationController(Document* document) ScriptedAnimationController::ScriptedAnimationController(Document* document)
...@@ -111,7 +127,7 @@ void ScriptedAnimationController::DispatchEvents( ...@@ -111,7 +127,7 @@ void ScriptedAnimationController::DispatchEvents(
HeapVector<Member<Event>> remaining; HeapVector<Member<Event>> remaining;
for (auto& event : event_queue_) { for (auto& event : event_queue_) {
if (event && event->InterfaceName() == event_interface_filter) { if (event && event->InterfaceName() == event_interface_filter) {
per_frame_events_.erase(EventTargetKey(event.Get())); EraseFromPerFrameEventsMap(event.Get());
events.push_back(event.Release()); events.push_back(event.Release());
} else { } else {
remaining.push_back(event.Release()); remaining.push_back(event.Release());
...@@ -241,7 +257,7 @@ void ScriptedAnimationController::EnqueueEvent(Event* event) { ...@@ -241,7 +257,7 @@ void ScriptedAnimationController::EnqueueEvent(Event* event) {
} }
void ScriptedAnimationController::EnqueuePerFrameEvent(Event* event) { void ScriptedAnimationController::EnqueuePerFrameEvent(Event* event) {
if (!per_frame_events_.insert(EventTargetKey(event)).is_new_entry) if (!InsertToPerFrameEventsMap(event))
return; return;
EnqueueEvent(event); EnqueueEvent(event);
} }
......
...@@ -106,11 +106,15 @@ class CORE_EXPORT ScriptedAnimationController ...@@ -106,11 +106,15 @@ class CORE_EXPORT ScriptedAnimationController
Document* GetDocument() const { return To<Document>(GetExecutionContext()); } Document* GetDocument() const { return To<Document>(GetExecutionContext()); }
ALWAYS_INLINE bool InsertToPerFrameEventsMap(const Event* event);
ALWAYS_INLINE void EraseFromPerFrameEventsMap(const Event* event);
FrameRequestCallbackCollection callback_collection_; FrameRequestCallbackCollection callback_collection_;
Vector<base::OnceClosure> task_queue_; Vector<base::OnceClosure> task_queue_;
HeapVector<Member<Event>> event_queue_; HeapVector<Member<Event>> event_queue_;
HeapListHashSet<std::pair<Member<const EventTarget>, const StringImpl*>> using PerFrameEventsMap =
per_frame_events_; HeapHashMap<Member<const EventTarget>, HashSet<const StringImpl*>>;
PerFrameEventsMap per_frame_events_;
using MediaQueryListListeners = using MediaQueryListListeners =
HeapListHashSet<Member<MediaQueryListListener>>; HeapListHashSet<Member<MediaQueryListListener>>;
MediaQueryListListeners media_query_list_listeners_; MediaQueryListListeners media_query_list_listeners_;
......
...@@ -246,8 +246,8 @@ class ListHashSet ...@@ -246,8 +246,8 @@ class ListHashSet
ValueType Take(ValuePeekInType); ValueType Take(ValuePeekInType);
ValueType TakeFirst(); ValueType TakeFirst();
template <typename VisitorDispatcher> template <typename VisitorDispatcher, typename A = AllocatorArg>
void Trace(VisitorDispatcher); std::enable_if_t<A::kIsGarbageCollected> Trace(VisitorDispatcher);
protected: protected:
typename ImplType::ValueType** GetBufferSlot() { typename ImplType::ValueType** GetBufferSlot() {
...@@ -1203,8 +1203,9 @@ void ListHashSet<T, inlineCapacity, U, V>::DeleteAllNodes() { ...@@ -1203,8 +1203,9 @@ void ListHashSet<T, inlineCapacity, U, V>::DeleteAllNodes() {
} }
template <typename T, size_t inlineCapacity, typename U, typename V> template <typename T, size_t inlineCapacity, typename U, typename V>
template <typename VisitorDispatcher> template <typename VisitorDispatcher, typename A>
void ListHashSet<T, inlineCapacity, U, V>::Trace(VisitorDispatcher visitor) { std::enable_if_t<A::kIsGarbageCollected>
ListHashSet<T, inlineCapacity, U, V>::Trace(VisitorDispatcher visitor) {
if (visitor->ConcurrentTracingBailOut( if (visitor->ConcurrentTracingBailOut(
{this, [](blink::Visitor* visitor, void* object) { {this, [](blink::Visitor* visitor, void* object) {
reinterpret_cast<ListHashSet<T, inlineCapacity, U, V>*>(object) reinterpret_cast<ListHashSet<T, inlineCapacity, U, V>*>(object)
......
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