Fix bug # 12459: nsWindowMediator optimizations (put it on a diet). r=tingley, verbal sr=ben

This commit is contained in:
rjc%netscape.com 2002-02-12 22:48:44 +00:00
Родитель 024fbdd7a3
Коммит 82d9f6fee3
2 изменённых файлов: 27 добавлений и 59 удалений

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

@ -93,24 +93,6 @@ static void GetAttribute( nsIXULWindow* inWindow,
static void GetWindowType( nsIXULWindow* inWindow, nsAutoString& outType); static void GetWindowType( nsIXULWindow* inWindow, nsAutoString& outType);
static inline PRUint32 GetWindowZ( nsIXULWindow *inWindow); static inline PRUint32 GetWindowZ( nsIXULWindow *inWindow);
static nsresult NS_NewMediatorListRDFContainer(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource,
nsIRDFContainer** aResult)
{
nsresult rv;
rv = nsComponentManager::CreateInstance(
kRDFContainerCID, NULL, NS_GET_IID(nsIRDFContainer), (void**)aResult);
if (NS_FAILED(rv))
return rv;
rv = (*aResult)->Init(aDataSource, aResource);
if (NS_FAILED(rv))
{
NS_RELEASE(*aResult);
}
return rv;
}
nsresult GetDOMWindow( nsIXULWindow* inWindow, nsCOMPtr< nsIDOMWindowInternal>& outDOMWindow) nsresult GetDOMWindow( nsIXULWindow* inWindow, nsCOMPtr< nsIDOMWindowInternal>& outDOMWindow)
{ {
@ -187,6 +169,7 @@ nsIRDFResource *nsWindowMediator::kNC_URL = NULL;
nsIRDFResource *nsWindowMediator::kNC_KeyIndex = NULL; nsIRDFResource *nsWindowMediator::kNC_KeyIndex = NULL;
PRInt32 nsWindowMediator::gRefCnt; PRInt32 nsWindowMediator::gRefCnt;
nsIRDFContainer *nsWindowMediator::mContainer = NULL;
nsIRDFDataSource *nsWindowMediator::mInner = NULL; nsIRDFDataSource *nsWindowMediator::mInner = NULL;
@ -220,6 +203,7 @@ nsWindowMediator::~nsWindowMediator()
NS_IF_RELEASE(kNC_Name); NS_IF_RELEASE(kNC_Name);
NS_IF_RELEASE(kNC_URL); NS_IF_RELEASE(kNC_URL);
NS_IF_RELEASE(kNC_KeyIndex); NS_IF_RELEASE(kNC_KeyIndex);
NS_IF_RELEASE(mContainer);
NS_IF_RELEASE(mInner); NS_IF_RELEASE(mInner);
if (mListLock) if (mListLock)
PR_DestroyLock(mListLock); PR_DestroyLock(mListLock);
@ -283,10 +267,7 @@ NS_IMETHODIMP nsWindowMediator::UnregisterWindow(nsWindowInfo *inInfo)
((nsAppShellWindowEnumerator*)mEnumeratorList[index])->WindowRemoved(inInfo); ((nsAppShellWindowEnumerator*)mEnumeratorList[index])->WindowRemoved(inInfo);
// Remove From RDF // Remove From RDF
nsCOMPtr<nsIRDFContainer> container; mContainer->RemoveElement(inInfo->mRDFID, PR_TRUE);
nsresult rv = NS_NewMediatorListRDFContainer(mInner, kNC_WindowMediatorRoot, getter_AddRefs(container));
if (NS_SUCCEEDED(rv))
container->RemoveElement(inInfo->mRDFID, PR_TRUE);
// Remove from the lists and free up // Remove from the lists and free up
if (inInfo == mOldestWindow) if (inInfo == mOldestWindow)
@ -810,37 +791,33 @@ nsWindowMediator::Init()
if (gRefCnt++ == 0) { if (gRefCnt++ == 0) {
mListLock = PR_NewLock(); mListLock = PR_NewLock();
if (!mListLock) if (!mListLock)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
rv = nsServiceManager::GetService( kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &gRDFService ); rv = nsServiceManager::GetService( kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &gRDFService );
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if ( gRDFService == NULL )
return NS_ERROR_NULL_POINTER;
gRDFService->GetResource( kURINC_WindowMediatorRoot, &kNC_WindowMediatorRoot ); gRDFService->GetResource( kURINC_WindowMediatorRoot, &kNC_WindowMediatorRoot );
gRDFService->GetResource( kURINC_Name, &kNC_Name ); gRDFService->GetResource( kURINC_Name, &kNC_Name );
gRDFService->GetResource( kURINC_URL, &kNC_URL ); gRDFService->GetResource( kURINC_URL, &kNC_URL );
gRDFService->GetResource( kURINC_KeyIndex, &kNC_KeyIndex ); gRDFService->GetResource( kURINC_KeyIndex, &kNC_KeyIndex );
rv = CallCreateInstance(kRDFInMemoryDataSourceCID, &mInner);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIRDFContainerUtils> rdfc = do_GetService(kRDFContainerUtilsCID, &rv);
if (NS_FAILED(rv))
return rv;
rv = rdfc->MakeSeq(mInner, kNC_WindowMediatorRoot, &mContainer );
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to make NC:WindowMediatorRoot a sequence");
if (NS_FAILED(rv))
return rv;
} }
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
NS_GET_IID(nsIRDFDataSource),
(void**) &mInner)))
return rv;
nsCOMPtr<nsIRDFContainerUtils> rdfc =
do_GetService(kRDFContainerUtilsCID, &rv);
if (NS_FAILED(rv))
return rv;
rv = rdfc->MakeSeq(mInner, kNC_WindowMediatorRoot, NULL );
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to make NC:WindowMediatorRoot a sequence");
if (NS_FAILED(rv))
return rv;
if ( gRDFService == NULL )
return NS_ERROR_NULL_POINTER;
mWatcher = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv); mWatcher = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
@ -856,14 +833,8 @@ NS_IMETHODIMP nsWindowMediator::GetTarget(nsIRDFResource* source,
{ {
if (property == kNC_KeyIndex) if (property == kNC_KeyIndex)
{ {
nsCOMPtr<nsIRDFContainer> container; PRInt32 theIndex = 0;
nsresult rv = NS_NewMediatorListRDFContainer(mInner, nsresult rv = mContainer->IndexOf(source, &theIndex);
kNC_WindowMediatorRoot, getter_AddRefs(container));
if (NS_FAILED(rv)) return(rv);
if (!container) return(NS_ERROR_FAILURE);
PRInt32 theIndex = 0;
rv = container->IndexOf(source, &theIndex);
if (NS_FAILED(rv)) return(rv); if (NS_FAILED(rv)) return(rv);
// only allow the range of 1 to 9 for single key access // only allow the range of 1 to 9 for single key access
@ -988,12 +959,7 @@ nsresult nsWindowMediator::AddWindowToRDF( nsWindowInfo* ioWindowInfo )
} }
#endif #endif
// Add the element to the container // Add the element to the container
nsCOMPtr<nsIRDFContainer> container; if (NS_FAILED(rv = mContainer->AppendElement( window ) ) /* rdf_ContainerAppendElement(mInner, kNC_WindowMediatorRoot, window) */ )
rv = NS_NewMediatorListRDFContainer(mInner, kNC_WindowMediatorRoot, getter_AddRefs(container));
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv = container->AppendElement( window ) ) /* rdf_ContainerAppendElement(mInner, kNC_WindowMediatorRoot, window) */ )
{ {
NS_ERROR("unable to add window to container"); NS_ERROR("unable to add window to container");
return rv; return rv;

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

@ -45,6 +45,7 @@
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsIRDFObserver.h" #include "nsIRDFObserver.h"
#include "nsIRDFContainer.h"
#include "nsIRDFDataSource.h" #include "nsIRDFDataSource.h"
class nsAppShellWindowEnumerator; class nsAppShellWindowEnumerator;
@ -219,6 +220,7 @@ private:
static nsIRDFResource* kNC_URL; static nsIRDFResource* kNC_URL;
static nsIRDFResource* kNC_KeyIndex; static nsIRDFResource* kNC_KeyIndex;
static PRInt32 gRefCnt; static PRInt32 gRefCnt;
static nsIRDFContainer* mContainer;
static nsIRDFDataSource* mInner; static nsIRDFDataSource* mInner;
}; };