Bug 795086 - Make nsConsoleService only post a LogMessageRunnable to the event queue if there are any observers for it. r=bz

This commit is contained in:
Seth Fowler 2012-09-28 09:54:36 -07:00
Родитель c5fbc6a7a9
Коммит 21dd8087c0
1 изменённых файлов: 12 добавлений и 4 удалений

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

@ -135,7 +135,7 @@ nsConsoleService::LogMessage(nsIConsoleMessage *message)
return NS_ERROR_FAILURE;
}
nsRefPtr<LogMessageRunnable> r = new LogMessageRunnable(message, this);
nsRefPtr<LogMessageRunnable> r;
nsIConsoleMessage *retiredMessage;
NS_ADDREF(message); // early, in case it's same as replaced below.
@ -180,14 +180,22 @@ nsConsoleService::LogMessage(nsIConsoleMessage *message)
/*
* Copy the listeners into the snapshot array - in case a listener
* is removed during an Observe(...) notification...
* is removed during an Observe(...) notification. If there are no
* listeners, don't bother to create the Runnable, since we don't
* need to run it and it will hold onto the memory for the message
* unnecessarily.
*/
mListeners.EnumerateRead(CollectCurrentListeners, r);
if (mListeners.Count() > 0) {
r = new LogMessageRunnable(message, this);
mListeners.EnumerateRead(CollectCurrentListeners, r);
}
}
if (retiredMessage != nullptr)
NS_RELEASE(retiredMessage);
NS_DispatchToMainThread(r);
if (r)
NS_DispatchToMainThread(r);
return NS_OK;
}