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 @@
namespace blink {
std::pair<EventTarget*, StringImpl*> EventTargetKey(const Event* event) {
return std::make_pair(event->target(), event->type().Impl());
bool ScriptedAnimationController::InsertToPerFrameEventsMap(
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)
......@@ -111,7 +127,7 @@ void ScriptedAnimationController::DispatchEvents(
HeapVector<Member<Event>> remaining;
for (auto& event : event_queue_) {
if (event && event->InterfaceName() == event_interface_filter) {
per_frame_events_.erase(EventTargetKey(event.Get()));
EraseFromPerFrameEventsMap(event.Get());
events.push_back(event.Release());
} else {
remaining.push_back(event.Release());
......@@ -241,7 +257,7 @@ void ScriptedAnimationController::EnqueueEvent(Event* event) {
}
void ScriptedAnimationController::EnqueuePerFrameEvent(Event* event) {
if (!per_frame_events_.insert(EventTargetKey(event)).is_new_entry)
if (!InsertToPerFrameEventsMap(event))
return;
EnqueueEvent(event);
}
......
......@@ -106,11 +106,15 @@ class CORE_EXPORT ScriptedAnimationController
Document* GetDocument() const { return To<Document>(GetExecutionContext()); }
ALWAYS_INLINE bool InsertToPerFrameEventsMap(const Event* event);
ALWAYS_INLINE void EraseFromPerFrameEventsMap(const Event* event);
FrameRequestCallbackCollection callback_collection_;
Vector<base::OnceClosure> task_queue_;
HeapVector<Member<Event>> event_queue_;
HeapListHashSet<std::pair<Member<const EventTarget>, const StringImpl*>>
per_frame_events_;
using PerFrameEventsMap =
HeapHashMap<Member<const EventTarget>, HashSet<const StringImpl*>>;
PerFrameEventsMap per_frame_events_;
using MediaQueryListListeners =
HeapListHashSet<Member<MediaQueryListListener>>;
MediaQueryListListeners media_query_list_listeners_;
......
......@@ -246,8 +246,8 @@ class ListHashSet
ValueType Take(ValuePeekInType);
ValueType TakeFirst();
template <typename VisitorDispatcher>
void Trace(VisitorDispatcher);
template <typename VisitorDispatcher, typename A = AllocatorArg>
std::enable_if_t<A::kIsGarbageCollected> Trace(VisitorDispatcher);
protected:
typename ImplType::ValueType** GetBufferSlot() {
......@@ -1203,8 +1203,9 @@ void ListHashSet<T, inlineCapacity, U, V>::DeleteAllNodes() {
}
template <typename T, size_t inlineCapacity, typename U, typename V>
template <typename VisitorDispatcher>
void ListHashSet<T, inlineCapacity, U, V>::Trace(VisitorDispatcher visitor) {
template <typename VisitorDispatcher, typename A>
std::enable_if_t<A::kIsGarbageCollected>
ListHashSet<T, inlineCapacity, U, V>::Trace(VisitorDispatcher visitor) {
if (visitor->ConcurrentTracingBailOut(
{this, [](blink::Visitor* visitor, void* 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