Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(599)

Unified Diff: Source/core/dom/MutationObserver.cpp

Issue 142193004: Create & use microtask work queue (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ws Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Source/core/dom/Microtask.cpp ('K') | « Source/core/dom/MutationObserver.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/MutationObserver.cpp
diff --git a/Source/core/dom/MutationObserver.cpp b/Source/core/dom/MutationObserver.cpp
index 4402477d9e6fc8674f65f8df1b94c70a8dda4f40..d84544267c3e28d251ccbecdd91efbb21924bef6 100644
--- a/Source/core/dom/MutationObserver.cpp
+++ b/Source/core/dom/MutationObserver.cpp
@@ -36,6 +36,7 @@
#include "bindings/v8/ExceptionState.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/Microtask.h"
#include "core/dom/MutationCallback.h"
#include "core/dom/MutationObserverRegistration.h"
#include "core/dom/MutationRecord.h"
@@ -182,18 +183,27 @@ static MutationObserverSet& suspendedMutationObservers()
return suspendedObservers;
}
+static void activateObserver(PassRefPtr<MutationObserver> observer)
+{
+ MutationObserverSet& active = activeMutationObservers();
adamk 2014/01/29 22:58:24 Nit: No need to save this into a local, you can ju
rafaelw 2014/01/29 23:18:52 Done.
+ if (active.isEmpty())
+ Microtask::enqueueMicrotask(&MutationObserver::deliverMutations);
+
+ activeMutationObservers().add(observer);
+}
+
void MutationObserver::enqueueMutationRecord(PassRefPtr<MutationRecord> mutation)
{
ASSERT(isMainThread());
m_records.append(mutation);
- activeMutationObservers().add(this);
+ activateObserver(this);
InspectorInstrumentation::didEnqueueMutationRecord(m_callback->executionContext(), this);
}
void MutationObserver::setHasTransientRegistration()
{
ASSERT(isMainThread());
- activeMutationObservers().add(this);
+ activateObserver(this);
}
HashSet<Node*> MutationObserver::getObservedNodes() const
@@ -234,7 +244,7 @@ void MutationObserver::deliver()
InspectorInstrumentation::didDeliverMutationRecords(m_callback->executionContext());
}
-void MutationObserver::deliverAllMutations()
+void MutationObserver::deliverMutations()
{
ASSERT(isMainThread());
static bool deliveryInProgress = false;
adamk 2014/01/29 22:58:24 Can you remove this bool while you're at it?
rafaelw 2014/01/29 23:18:52 Sorry. Yes. Had this is my prototype, but failed t
@@ -250,21 +260,19 @@ void MutationObserver::deliverAllMutations()
continue;
suspendedMutationObservers().remove(suspended[i]);
- activeMutationObservers().add(suspended[i]);
+ activateObserver(suspended[i]);
}
}
- while (!activeMutationObservers().isEmpty()) {
- Vector<RefPtr<MutationObserver> > observers;
- copyToVector(activeMutationObservers(), observers);
- activeMutationObservers().clear();
- std::sort(observers.begin(), observers.end(), ObserverLessThan());
- for (size_t i = 0; i < observers.size(); ++i) {
- if (observers[i]->canDeliver())
- observers[i]->deliver();
- else
- suspendedMutationObservers().add(observers[i]);
- }
+ Vector<RefPtr<MutationObserver> > observers;
+ copyToVector(activeMutationObservers(), observers);
+ activeMutationObservers().clear();
+ std::sort(observers.begin(), observers.end(), ObserverLessThan());
+ for (size_t i = 0; i < observers.size(); ++i) {
+ if (observers[i]->canDeliver())
+ observers[i]->deliver();
+ else
+ suspendedMutationObservers().add(observers[i]);
}
deliveryInProgress = false;
« Source/core/dom/Microtask.cpp ('K') | « Source/core/dom/MutationObserver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698