Bug 803665 - followup - dispense with nsGlobalWindow::{First,Last}Timeout and nsTimeout::{Next,Previous}; r=bz

This commit is contained in:
Nathan Froyd 2012-11-01 10:07:22 -04:00
Родитель 0fb97bb8ee
Коммит f4ba419a2e
2 изменённых файлов: 20 добавлений и 34 удалений

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

@ -1238,9 +1238,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mListenerManager,
nsEventListenerManager)
for (nsTimeout* timeout = tmp->FirstTimeout();
for (nsTimeout* timeout = tmp->mTimeouts.getFirst();
timeout;
timeout = timeout->Next()) {
timeout = timeout->getNext()) {
cb.NoteNativeChild(timeout, NS_CYCLE_COLLECTION_PARTICIPANT(nsTimeout));
}
@ -1345,7 +1345,9 @@ nsGlobalWindow::IsBlackForCC()
void
nsGlobalWindow::UnmarkGrayTimers()
{
for (nsTimeout* timeout = FirstTimeout(); timeout; timeout = timeout->Next()) {
for (nsTimeout* timeout = mTimeouts.getFirst();
timeout;
timeout = timeout->getNext()) {
if (timeout->mScriptHandler) {
JSObject* o = timeout->mScriptHandler->GetScriptObject();
xpc_UnmarkGrayObject(o);
@ -9822,7 +9824,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
// timeout events fire "early", so we need to test the timer as well
// as the deadline.
last_expired_timeout = nullptr;
for (timeout = FirstTimeout(); timeout; timeout = timeout->Next()) {
for (timeout = mTimeouts.getFirst(); timeout; timeout = timeout->getNext()) {
if (((timeout == aTimeout) || (timeout->mWhen <= deadline)) &&
(timeout->mFiringDepth == 0)) {
// Mark any timeouts that are on the list to be fired with the
@ -9870,10 +9872,10 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
Telemetry::AutoCounter<Telemetry::DOM_TIMERS_FIRED_PER_NATIVE_TIMEOUT> timeoutsRan;
for (timeout = FirstTimeout();
for (timeout = mTimeouts.getFirst();
timeout != &dummy_timeout && !IsFrozen();
timeout = nextTimeout) {
nextTimeout = timeout->Next();
nextTimeout = timeout->getNext();
if (timeout->mFiringDepth != firingDepth) {
// We skip the timeout since it's on the list to run at another
@ -9937,7 +9939,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
// Running a timeout can cause another timeout to be deleted, so
// we need to reset the pointer to the following timeout.
nextTimeout = timeout->Next();
nextTimeout = timeout->getNext();
timeout->remove();
@ -9990,7 +9992,7 @@ nsGlobalWindow::ClearTimeoutOrInterval(int32_t aTimerID)
uint32_t public_id = (uint32_t)aTimerID;
nsTimeout *timeout;
for (timeout = FirstTimeout(); timeout; timeout = timeout->Next()) {
for (timeout = mTimeouts.getFirst(); timeout; timeout = timeout->getNext()) {
if (timeout->mPublicId == public_id) {
if (timeout->mRunning) {
/* We're running from inside the timeout. Mark this
@ -10035,13 +10037,13 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
// start at the timer after mTimeoutInsertionPoint, if there is one.
// Otherwise, start at the beginning of the list.
for (nsTimeout *timeout = mTimeoutInsertionPoint ?
mTimeoutInsertionPoint->Next() : FirstTimeout();
mTimeoutInsertionPoint->getNext() : mTimeouts.getFirst();
timeout; ) {
// It's important that this check be <= so that we guarantee that
// taking NS_MAX with |now| won't make a quantity equal to
// timeout->mWhen below.
if (timeout->mWhen <= now) {
timeout = timeout->Next();
timeout = timeout->getNext();
continue;
}
@ -10078,7 +10080,7 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
// Get the pointer to the next timeout now, before we move the
// current timeout in the list.
nsTimeout* nextTimeout = timeout->Next();
nsTimeout* nextTimeout = timeout->getNext();
// It is safe to remove and re-insert because mWhen is now
// strictly smaller than it used to be, so we know we'll insert
@ -10102,7 +10104,7 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
timeout = nextTimeout;
} else {
timeout = timeout->Next();
timeout = timeout->getNext();
}
}
@ -10114,7 +10116,7 @@ nsGlobalWindow::ClearAllTimeouts()
{
nsTimeout *timeout, *nextTimeout;
for (timeout = FirstTimeout(); timeout; timeout = nextTimeout) {
for (timeout = mTimeouts.getFirst(); timeout; timeout = nextTimeout) {
/* If RunTimeout() is higher up on the stack for this
window, e.g. as a result of document.write from a timeout,
then we need to reset the list insertion point for
@ -10123,7 +10125,7 @@ nsGlobalWindow::ClearAllTimeouts()
if (mRunningTimeout == timeout)
mTimeoutInsertionPoint = nullptr;
nextTimeout = timeout->Next();
nextTimeout = timeout->getNext();
if (timeout->mTimer) {
timeout->mTimer->Cancel();
@ -10156,14 +10158,14 @@ nsGlobalWindow::InsertTimeoutIntoList(nsTimeout *aTimeout)
// mTimeoutInsertionPoint, though. This optimizes for the common case of
// insertion at the end.
nsTimeout* prevSibling;
for (prevSibling = LastTimeout();
for (prevSibling = mTimeouts.getLast();
prevSibling && prevSibling != mTimeoutInsertionPoint &&
// This condition needs to match the one in SetTimeoutOrInterval that
// determines whether to set mWhen or mTimeRemaining.
((IsFrozen() || mTimeoutsSuspendDepth) ?
prevSibling->mTimeRemaining > aTimeout->mTimeRemaining :
prevSibling->mWhen > aTimeout->mWhen);
prevSibling = prevSibling->Prev()) {
prevSibling = prevSibling->getPrevious()) {
/* Do nothing; just searching */
}
@ -10464,7 +10466,7 @@ nsGlobalWindow::SuspendTimeouts(uint32_t aIncrease,
mozilla::dom::workers::SuspendWorkersForWindow(cx, this);
TimeStamp now = TimeStamp::Now();
for (nsTimeout *t = FirstTimeout(); t; t = t->Next()) {
for (nsTimeout *t = mTimeouts.getFirst(); t; t = t->getNext()) {
// Set mTimeRemaining to be the time remaining for this timer.
if (t->mWhen > now)
t->mTimeRemaining = t->mWhen - now;
@ -10552,7 +10554,7 @@ nsGlobalWindow::ResumeTimeouts(bool aThawChildren)
bool _seenDummyTimeout = false;
#endif
for (nsTimeout *t = FirstTimeout(); t; t = t->Next()) {
for (nsTimeout *t = mTimeouts.getFirst(); t; t = t->getNext()) {
// There's a chance we're being called with RunTimeout on the stack in which
// case we have a dummy timeout in the list that *must not* be resumed. It
// can be identified by a null mWindow.

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

@ -149,14 +149,6 @@ struct nsTimeout : mozilla::LinkedListElement<nsTimeout>
nsrefcnt Release();
nsrefcnt AddRef();
nsTimeout* Next() {
return getNext();
}
nsTimeout* Prev() {
return getPrevious();
}
nsresult InitTimer(nsTimerCallbackFunc aFunc, uint64_t delay) {
return mTimer->InitWithFuncCallback(aFunc, this, delay,
nsITimer::TYPE_ONE_SHOT);
@ -883,14 +875,6 @@ protected:
bool IsInModalState();
nsTimeout* FirstTimeout() {
return mTimeouts.getFirst();
}
nsTimeout* LastTimeout() {
return mTimeouts.getLast();
}
// Convenience functions for the many methods that need to scale
// from device to CSS pixels or vice versa. Note: if a presentation
// context is not available, they will assume a 1:1 ratio.