Bug 1186785 - Replace nsBaseHashtable::EnumerateRead() calls in toolkit/ with iterators. r=froydnj.

--HG--
extra : rebase_source : d472ec1638cb1697af0d2f2dbae4f4229bea1a80
This commit is contained in:
Nicholas Nethercote 2015-10-19 15:46:46 -07:00
parent 5b34a25af2
commit 343f285eca
5 changed files with 50 additions and 96 deletions

View File

@ -1,3 +1,5 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -250,21 +252,6 @@ private:
nsCOMPtr<nsIThread> mWorkerThread;
};
/**
* An helper callback function used to print information about any
* pending watch when shutting down the nsINativeFileWatcher service.
*/
static PLDHashOperator
WatchedPathsInfoHashtableTraverser(nsVoidPtrHashKey::KeyType key,
WatchedResourceDescriptor* watchedResource,
void* userArg)
{
FILEWATCHERLOG("NativeFileWatcherIOTask::DeactivateRunnableMethod - "
"%S is still being watched.", watchedResource->mPath.get());
return PL_DHASH_NEXT;
}
/**
* This runnable is dispatched from the main thread to get the notifications of the
* changes in the watched resources by continuously calling the blocking function
@ -855,8 +842,11 @@ NativeFileWatcherIOTask::DeactivateRunnableMethod()
"watches manually before quitting.");
// Log any pending watch.
(void)mWatchedResourcesByHandle.EnumerateRead(
&WatchedPathsInfoHashtableTraverser, nullptr);
for (auto it = mWatchedResourcesByHandle.Iter(); !it.Done(); it.Next()) {
FILEWATCHERLOG("NativeFileWatcherIOTask::DeactivateRunnableMethod - "
"%S is still being watched.", it.UserData()->mPath.get());
}
// We return immediately if |mShuttingDown| is true (see below for
// details about the shutdown protocol being followed).

View File

@ -1,4 +1,5 @@
//* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -2152,19 +2153,6 @@ nsNavHistory::ConstructQueryString(
return NS_OK;
}
PLDHashOperator BindAdditionalParameter(nsNavHistory::StringHash::KeyType aParamName,
nsCString aParamValue,
void* aStatement)
{
mozIStorageStatement* stmt = static_cast<mozIStorageStatement*>(aStatement);
nsresult rv = stmt->BindUTF8StringByName(aParamName, aParamValue);
if (NS_FAILED(rv))
return PL_DHASH_STOP;
return PL_DHASH_NEXT;
}
// nsNavHistory::GetQueryResults
//
// Call this to get the results from a complex query. This is used by
@ -2221,7 +2209,12 @@ nsNavHistory::GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
}
}
addParams.EnumerateRead(BindAdditionalParameter, statement.get());
for (auto iter = addParams.Iter(); !iter.Done(); iter.Next()) {
nsresult rv = statement->BindUTF8StringByName(iter.Key(), iter.Data());
if (NS_FAILED(rv)) {
break;
}
}
// Optimize the case where there is no need for any post-query filtering.
if (NeedToFilterResultSet(aQueries, aOptions)) {
@ -3047,7 +3040,13 @@ nsNavHistory::AsyncExecuteLegacyQueries(nsINavHistoryQuery** aQueries,
NS_ENSURE_SUCCESS(rv, rv);
}
}
addParams.EnumerateRead(BindAdditionalParameter, statement.get());
for (auto iter = addParams.Iter(); !iter.Done(); iter.Next()) {
nsresult rv = statement->BindUTF8StringByName(iter.Key(), iter.Data());
if (NS_FAILED(rv)) {
break;
}
}
rv = statement->ExecuteAsync(aCallback, _stmt);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -43,23 +43,13 @@ nsGTKRemoteService::Startup(const char* aAppName, const char* aProfileName)
gtk_widget_realize(mServerWindow);
HandleCommandsFor(mServerWindow, nullptr);
mWindows.EnumerateRead(StartupHandler, this);
for (auto iter = mWindows.Iter(); !iter.Done(); iter.Next()) {
HandleCommandsFor(iter.Key(), iter.UserData());
}
return NS_OK;
}
PLDHashOperator
nsGTKRemoteService::StartupHandler(GtkWidget* aKey,
nsIWeakReference* aData,
void* aClosure)
{
GtkWidget* widget = (GtkWidget*) aKey;
nsGTKRemoteService* aThis = (nsGTKRemoteService*) aClosure;
aThis->HandleCommandsFor(widget, aData);
return PL_DHASH_NEXT;
}
static nsIWidget* GetMainWidget(nsIDOMWindow* aWindow)
{
// get the native window for this instance

View File

@ -34,11 +34,6 @@ private:
nsIWeakReference* aWindow);
static PLDHashOperator StartupHandler(GtkWidget* aKey,
nsIWeakReference* aData,
void* aClosure);
static gboolean HandlePropertyChange(GtkWidget *widget,
GdkEventProperty *event,
nsIWeakReference* aThis);

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -1708,23 +1709,6 @@ IsInWhitelist(const nsACString& key)
return false;
}
static PLDHashOperator EnumerateEntries(const nsACString& key,
nsCString entry,
void* userData)
{
if (!entry.IsEmpty()) {
NS_NAMED_LITERAL_CSTRING(kEquals, "=");
NS_NAMED_LITERAL_CSTRING(kNewline, "\n");
nsAutoCString line = key + kEquals + entry + kNewline;
crashReporterAPIData->Append(line);
if (IsInWhitelist(key)) {
crashEventAPIData->Append(line);
}
}
return PL_DHASH_NEXT;
}
// This function is miscompiled with MSVC 2005/2008 when PGO is on.
#ifdef _MSC_VER
#pragma optimize("", off)
@ -1818,7 +1802,20 @@ nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data)
// now rebuild the file contents
crashReporterAPIData->Truncate(0);
crashEventAPIData->Truncate(0);
crashReporterAPIData_Hash->EnumerateRead(EnumerateEntries, nullptr);
for (auto it = crashReporterAPIData_Hash->Iter(); !it.Done(); it.Next()) {
const nsACString& key = it.Key();
nsCString entry = it.Data();
if (!entry.IsEmpty()) {
NS_NAMED_LITERAL_CSTRING(kEquals, "=");
NS_NAMED_LITERAL_CSTRING(kNewline, "\n");
nsAutoCString line = key + kEquals + entry + kNewline;
crashReporterAPIData->Append(line);
if (IsInWhitelist(key)) {
crashEventAPIData->Append(line);
}
}
}
return NS_OK;
}
@ -2531,11 +2528,6 @@ struct Blacklist {
const int mLen;
};
struct EnumerateAnnotationsContext {
const Blacklist& blacklist;
PRFileDesc* fd;
};
static void
WriteAnnotation(PRFileDesc* fd, const nsACString& key, const nsACString& value)
{
@ -2545,24 +2537,6 @@ WriteAnnotation(PRFileDesc* fd, const nsACString& key, const nsACString& value)
PR_Write(fd, "\n", 1);
}
static PLDHashOperator
EnumerateAnnotations(const nsACString& key,
nsCString entry,
void* userData)
{
EnumerateAnnotationsContext* ctx =
static_cast<EnumerateAnnotationsContext*>(userData);
const Blacklist& blacklist = ctx->blacklist;
// skip entries in the blacklist
if (blacklist.Contains(key))
return PL_DHASH_NEXT;
WriteAnnotation(ctx->fd, key, entry);
return PL_DHASH_NEXT;
}
static bool
WriteExtraData(nsIFile* extraFile,
const AnnotationTable& data,
@ -2572,14 +2546,20 @@ WriteExtraData(nsIFile* extraFile,
{
PRFileDesc* fd;
int truncOrAppend = truncate ? PR_TRUNCATE : PR_APPEND;
nsresult rv =
nsresult rv =
extraFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | truncOrAppend,
0600, &fd);
if (NS_FAILED(rv))
return false;
EnumerateAnnotationsContext ctx = { blacklist, fd };
data.EnumerateRead(EnumerateAnnotations, &ctx);
for (auto iter = data.ConstIter(); !iter.Done(); iter.Next()) {
// Skip entries in the blacklist.
const nsACString& key = iter.Key();
if (blacklist.Contains(key)) {
continue;
}
WriteAnnotation(fd, key, iter.Data());
}
if (writeCrashTime) {
time_t crashTime = time(nullptr);