Fix to speed up nsURLProperties. r=ftang

This commit is contained in:
warren%netscape.com 2000-02-09 04:05:59 +00:00
Родитель 7e564704d4
Коммит 9b43ca8922
2 изменённых файлов: 21 добавлений и 1 удалений

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

@ -27,15 +27,27 @@
#include "nsNetUtil.h"
static NS_DEFINE_IID(kIPersistentPropertiesIID, NS_IPERSISTENTPROPERTIES_IID);
static NS_DEFINE_IID(kIOServiceCID, NS_IOSERVICE_CID);
nsIIOService* nsURLProperties::gIOService;
nsrefcnt nsURLProperties::gRefCnt = 0;
nsURLProperties::nsURLProperties(nsString& aUrl)
{
if (gRefCnt++ == 0) {
nsresult rv;
rv = nsServiceManager::GetService(kIOServiceCID,
NS_GET_IID(nsIIOService),
(nsISupports**)&gIOService);
NS_ASSERTION(NS_SUCCEEDED(rv), "can't get nsIOService");
}
mDelegate = nsnull;
nsresult res = NS_OK;
nsIURI* url = nsnull;
nsIInputStream* in = nsnull;
res = NS_NewURI(&url, aUrl, nsnull);
res = gIOService->NewURI(aUrl.GetBuffer(), nsnull, &url);
if (NS_FAILED(res)) return;
res = NS_OpenURI(&in, url);
@ -66,6 +78,10 @@ nsURLProperties::nsURLProperties(nsString& aUrl)
nsURLProperties::~nsURLProperties()
{
NS_IF_RELEASE(mDelegate);
if (--gRefCnt == 0) {
nsServiceManager::ReleaseService(kIOServiceCID, gIOService);
gIOService = nsnull;
}
}
NS_IMETHODIMP nsURLProperties::Get(const nsString& aKey, nsString& oValue)

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

@ -25,6 +25,7 @@
#include "nsIPersistentProperties.h"
#include "nsString.h"
#include "nsIIOService.h"
class nsURLProperties {
public:
@ -34,6 +35,9 @@ public:
NS_IMETHOD Get( const nsString& aKey, nsString& value);
private:
static nsIIOService* gIOService; // to speed up creating URLs
static nsrefcnt gRefCnt;
nsIPersistentProperties *mDelegate;
};