Bug 1087330. Make the data structure we use for our promise microtask queue have O(1) first element removal, not O(N). r=khuey

This commit is contained in:
Boris Zbarsky 2015-05-01 22:33:01 -04:00
Родитель 25dceb01f1
Коммит b8ba520783
3 изменённых файлов: 12 добавлений и 10 удалений

Просмотреть файл

@ -482,10 +482,10 @@ bool
Promise::PerformMicroTaskCheckpoint() Promise::PerformMicroTaskCheckpoint()
{ {
CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get(); CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get();
nsTArray<nsCOMPtr<nsIRunnable>>& microtaskQueue = std::queue<nsCOMPtr<nsIRunnable>>& microtaskQueue =
runtime->GetPromiseMicroTaskQueue(); runtime->GetPromiseMicroTaskQueue();
if (microtaskQueue.IsEmpty()) { if (microtaskQueue.empty()) {
return false; return false;
} }
@ -495,11 +495,11 @@ Promise::PerformMicroTaskCheckpoint()
} }
do { do {
nsCOMPtr<nsIRunnable> runnable = microtaskQueue.ElementAt(0); nsCOMPtr<nsIRunnable> runnable = microtaskQueue.front();
MOZ_ASSERT(runnable); MOZ_ASSERT(runnable);
// This function can re-enter, so we remove the element before calling. // This function can re-enter, so we remove the element before calling.
microtaskQueue.RemoveElementAt(0); microtaskQueue.pop();
nsresult rv = runnable->Run(); nsresult rv = runnable->Run();
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return false; return false;
@ -507,7 +507,7 @@ Promise::PerformMicroTaskCheckpoint()
if (cx.isSome()) { if (cx.isSome()) {
JS_CheckForInterrupt(cx.ref()); JS_CheckForInterrupt(cx.ref());
} }
} while (!microtaskQueue.IsEmpty()); } while (!microtaskQueue.empty());
return true; return true;
} }
@ -1168,10 +1168,10 @@ Promise::DispatchToMicroTask(nsIRunnable* aRunnable)
MOZ_ASSERT(aRunnable); MOZ_ASSERT(aRunnable);
CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get(); CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get();
nsTArray<nsCOMPtr<nsIRunnable>>& microtaskQueue = std::queue<nsCOMPtr<nsIRunnable>>& microtaskQueue =
runtime->GetPromiseMicroTaskQueue(); runtime->GetPromiseMicroTaskQueue();
microtaskQueue.AppendElement(aRunnable); microtaskQueue.push(aRunnable);
} }
#if defined(DOM_PROMISE_DEPRECATED_REPORTING) #if defined(DOM_PROMISE_DEPRECATED_REPORTING)

Просмотреть файл

@ -961,7 +961,7 @@ CycleCollectedJSRuntime::SetPendingException(nsIException* aException)
mPendingException = aException; mPendingException = aException;
} }
nsTArray<nsCOMPtr<nsIRunnable>>& std::queue<nsCOMPtr<nsIRunnable>>&
CycleCollectedJSRuntime::GetPromiseMicroTaskQueue() CycleCollectedJSRuntime::GetPromiseMicroTaskQueue()
{ {
return mPromiseMicroTaskQueue; return mPromiseMicroTaskQueue;

Просмотреть файл

@ -7,6 +7,8 @@
#ifndef mozilla_CycleCollectedJSRuntime_h__ #ifndef mozilla_CycleCollectedJSRuntime_h__
#define mozilla_CycleCollectedJSRuntime_h__ #define mozilla_CycleCollectedJSRuntime_h__
#include <queue>
#include "mozilla/DeferredFinalize.h" #include "mozilla/DeferredFinalize.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "jsapi.h" #include "jsapi.h"
@ -261,7 +263,7 @@ public:
already_AddRefed<nsIException> GetPendingException() const; already_AddRefed<nsIException> GetPendingException() const;
void SetPendingException(nsIException* aException); void SetPendingException(nsIException* aException);
nsTArray<nsCOMPtr<nsIRunnable>>& GetPromiseMicroTaskQueue(); std::queue<nsCOMPtr<nsIRunnable>>& GetPromiseMicroTaskQueue();
nsCycleCollectionParticipant* GCThingParticipant(); nsCycleCollectionParticipant* GCThingParticipant();
nsCycleCollectionParticipant* ZoneParticipant(); nsCycleCollectionParticipant* ZoneParticipant();
@ -322,7 +324,7 @@ private:
nsCOMPtr<nsIException> mPendingException; nsCOMPtr<nsIException> mPendingException;
nsTArray<nsCOMPtr<nsIRunnable>> mPromiseMicroTaskQueue; std::queue<nsCOMPtr<nsIRunnable>> mPromiseMicroTaskQueue;
OOMState mOutOfMemoryState; OOMState mOutOfMemoryState;
OOMState mLargeAllocationFailureState; OOMState mLargeAllocationFailureState;