Modified nsWebShell::GetLinkState to used a cached GlobalHistory service rather

than getting and releasing the service each time GetLinkState is called. Getting
the global history service shows up as a big hit during profiling because GetLinkState
gets called each time a link is encountered while resolving style contexts.
This commit is contained in:
kmcclusk%netscape.com 1999-06-07 21:26:10 +00:00
parent 1c79128849
commit 88ad480647
2 changed files with 34 additions and 18 deletions

View File

@ -113,6 +113,8 @@ void nsWebShell_SetUnixEventQueue(PLEventQueue* aEventQueue)
#endif /* OLD_EVENT_QUEUE */ #endif /* OLD_EVENT_QUEUE */
static NS_DEFINE_CID(kGlobalHistoryCID, NS_GLOBALHISTORY_CID);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
class nsWebShell : public nsIWebShell, class nsWebShell : public nsIWebShell,
@ -385,6 +387,7 @@ protected:
nsVoidArray mHistory; nsVoidArray mHistory;
PRInt32 mHistoryIndex; PRInt32 mHistoryIndex;
nsIGlobalHistory* mHistoryService;
nsString mTitle; nsString mTitle;
@ -540,10 +543,16 @@ nsWebShell::nsWebShell()
mHintCharset = ""; mHintCharset = "";
mHintCharsetSource = kCharsetUninitialized; mHintCharsetSource = kCharsetUninitialized;
mForceCharacterSet = ""; mForceCharacterSet = "";
mHistoryService = nsnull;
} }
nsWebShell::~nsWebShell() nsWebShell::~nsWebShell()
{ {
if (nsnull != mHistoryService) {
nsServiceManager::ReleaseService(kGlobalHistoryCID, mHistoryService);
mHistoryService = nsnull;
}
// Stop any pending document loads and destroy the loader... // Stop any pending document loads and destroy the loader...
if (nsnull != mDocLoader) { if (nsnull != mDocLoader) {
mDocLoader->Stop(); mDocLoader->Stop();
@ -2285,16 +2294,15 @@ nsWebShell:: GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
{ {
nsString URLSpec(aURLSpec); nsString URLSpec(aURLSpec);
aState = eLinkState_Unvisited; aState = eLinkState_Unvisited;
static NS_DEFINE_CID(kGlobalHistoryCID, NS_GLOBALHISTORY_CID);
nsresult rv; nsresult rv;
nsIGlobalHistory* history; // XXX: GlobalHistory is going to be moved out of the webshell into a more appropriate place.
rv = nsServiceManager::GetService(kGlobalHistoryCID, if (nsnull == mHistoryService) {
nsIGlobalHistory::GetIID(), rv = nsServiceManager::GetService(kGlobalHistoryCID,
(nsISupports**) &history); nsIGlobalHistory::GetIID(),
(nsISupports**) &mHistoryService);
}
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return NS_OK; // XXX Okay, we couldn't color the link. Big deal. return NS_OK; // XXX Okay, we couldn't color the link. Big deal.
@ -2314,7 +2322,7 @@ nsWebShell:: GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
if (url) { if (url) {
urlStr.ToCString(url, urlStr.Length() + 1); urlStr.ToCString(url, urlStr.Length() + 1);
rv = history->GetLastVisitDate(url, &lastVisitDate); rv = mHistoryService->GetLastVisitDate(url, &lastVisitDate);
if (url != buf) if (url != buf)
delete[] url; delete[] url;
@ -2323,7 +2331,7 @@ nsWebShell:: GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
rv = NS_ERROR_OUT_OF_MEMORY; rv = NS_ERROR_OUT_OF_MEMORY;
} }
nsServiceManager::ReleaseService(kGlobalHistoryCID, history); //XXX: Moved to destructor nsServiceManager::ReleaseService(kGlobalHistoryCID, mHistoryService);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;

View File

@ -113,6 +113,8 @@ void nsWebShell_SetUnixEventQueue(PLEventQueue* aEventQueue)
#endif /* OLD_EVENT_QUEUE */ #endif /* OLD_EVENT_QUEUE */
static NS_DEFINE_CID(kGlobalHistoryCID, NS_GLOBALHISTORY_CID);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
class nsWebShell : public nsIWebShell, class nsWebShell : public nsIWebShell,
@ -385,6 +387,7 @@ protected:
nsVoidArray mHistory; nsVoidArray mHistory;
PRInt32 mHistoryIndex; PRInt32 mHistoryIndex;
nsIGlobalHistory* mHistoryService;
nsString mTitle; nsString mTitle;
@ -540,10 +543,16 @@ nsWebShell::nsWebShell()
mHintCharset = ""; mHintCharset = "";
mHintCharsetSource = kCharsetUninitialized; mHintCharsetSource = kCharsetUninitialized;
mForceCharacterSet = ""; mForceCharacterSet = "";
mHistoryService = nsnull;
} }
nsWebShell::~nsWebShell() nsWebShell::~nsWebShell()
{ {
if (nsnull != mHistoryService) {
nsServiceManager::ReleaseService(kGlobalHistoryCID, mHistoryService);
mHistoryService = nsnull;
}
// Stop any pending document loads and destroy the loader... // Stop any pending document loads and destroy the loader...
if (nsnull != mDocLoader) { if (nsnull != mDocLoader) {
mDocLoader->Stop(); mDocLoader->Stop();
@ -2285,16 +2294,15 @@ nsWebShell:: GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
{ {
nsString URLSpec(aURLSpec); nsString URLSpec(aURLSpec);
aState = eLinkState_Unvisited; aState = eLinkState_Unvisited;
static NS_DEFINE_CID(kGlobalHistoryCID, NS_GLOBALHISTORY_CID);
nsresult rv; nsresult rv;
nsIGlobalHistory* history; // XXX: GlobalHistory is going to be moved out of the webshell into a more appropriate place.
rv = nsServiceManager::GetService(kGlobalHistoryCID, if (nsnull == mHistoryService) {
nsIGlobalHistory::GetIID(), rv = nsServiceManager::GetService(kGlobalHistoryCID,
(nsISupports**) &history); nsIGlobalHistory::GetIID(),
(nsISupports**) &mHistoryService);
}
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return NS_OK; // XXX Okay, we couldn't color the link. Big deal. return NS_OK; // XXX Okay, we couldn't color the link. Big deal.
@ -2314,7 +2322,7 @@ nsWebShell:: GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
if (url) { if (url) {
urlStr.ToCString(url, urlStr.Length() + 1); urlStr.ToCString(url, urlStr.Length() + 1);
rv = history->GetLastVisitDate(url, &lastVisitDate); rv = mHistoryService->GetLastVisitDate(url, &lastVisitDate);
if (url != buf) if (url != buf)
delete[] url; delete[] url;
@ -2323,7 +2331,7 @@ nsWebShell:: GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
rv = NS_ERROR_OUT_OF_MEMORY; rv = NS_ERROR_OUT_OF_MEMORY;
} }
nsServiceManager::ReleaseService(kGlobalHistoryCID, history); //XXX: Moved to destructor nsServiceManager::ReleaseService(kGlobalHistoryCID, mHistoryService);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;