From 448ecbd81b59bd4de58a0953deb12752acc1445f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sun, 1 Nov 2015 19:50:57 -0800 Subject: [PATCH] Bug 1186790 - Replace nsBaseHashtable::EnumerateRead() calls in xpfe/ with iterators. r=neil. --- .../windowds/nsWindowDataSource.cpp | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/xpfe/components/windowds/nsWindowDataSource.cpp b/xpfe/components/windowds/nsWindowDataSource.cpp index 519b7089f80..cdeb3a13423 100644 --- a/xpfe/components/windowds/nsWindowDataSource.cpp +++ b/xpfe/components/windowds/nsWindowDataSource.cpp @@ -265,23 +265,6 @@ nsWindowDataSource::OnCloseWindow(nsIXULWindow *window) return NS_OK; } -struct findWindowClosure { - nsIRDFResource* targetResource; - nsIXULWindow *resultWindow; -}; - -static PLDHashOperator -findWindow(nsIXULWindow* aWindow, nsIRDFResource* aResource, void* aClosure) -{ - findWindowClosure* closure = static_cast(aClosure); - - if (aResource == closure->targetResource) { - closure->resultWindow = aWindow; - return PL_DHASH_STOP; - } - return PL_DHASH_NEXT; -} - // nsIWindowDataSource implementation NS_IMETHODIMP @@ -297,20 +280,23 @@ nsWindowDataSource::GetWindowForResource(const char *aResourceString, getter_AddRefs(windowResource)); // now reverse-lookup in the hashtable - findWindowClosure closure = { windowResource.get(), nullptr }; - mWindowResources.EnumerateRead(findWindow, &closure); - if (closure.resultWindow) { + for (auto iter = mWindowResources.Iter(); !iter.Done(); iter.Next()) { + nsIXULWindow* window = iter.Key(); + nsIRDFResource* resource = iter.UserData(); - // this sucks, we have to jump through docshell to go from - // nsIXULWindow -> nsIDOMWindow - nsCOMPtr docShell; - closure.resultWindow->GetDocShell(getter_AddRefs(docShell)); + if (resource == windowResource) { + // This sucks, we have to jump through docshell to go from + // nsIXULWindow -> nsIDOMWindow. + nsCOMPtr docShell; + window->GetDocShell(getter_AddRefs(docShell)); - if (docShell) { - nsCOMPtr result = do_GetInterface(docShell); + if (docShell) { + nsCOMPtr result = do_GetInterface(docShell); - *aResult = result; - NS_IF_ADDREF(*aResult); + *aResult = result; + NS_IF_ADDREF(*aResult); + } + break; } }