fixes bug 115129 "stream loader optimizations" r=gagan, sr=brendan,dveditz

This commit is contained in:
darin%netscape.com 2001-12-14 22:54:56 +00:00
Родитель c739c5639b
Коммит a2d32b8e4e
4 изменённых файлов: 37 добавлений и 24 удалений

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

@ -699,7 +699,10 @@ nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
}
#endif
NS_ENSURE_TRUE(mJAR, NS_ERROR_NULL_POINTER);
return mJAR->GetInputStream(mJAREntry, aInputStream);
nsresult rv = mJAR->GetInputStream(mJAREntry, aInputStream);
if (NS_SUCCEEDED(rv))
(*aInputStream)->Available((PRUint32 *) &mContentLength);
return rv;
}
NS_IMETHODIMP

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

@ -117,10 +117,18 @@ nsStreamLoader::GetRequest(nsIRequest **aRequest)
return NS_OK;
}
NS_IMETHODIMP
nsStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
{
nsCOMPtr<nsIChannel> chan( do_QueryInterface(request) );
if (chan) {
PRInt32 contentLength = -1;
chan->GetContentLength(&contentLength);
if (contentLength >= 0) {
// preallocate buffer
mData.SetCapacity(contentLength + 1);
}
}
return NS_OK;
}
@ -141,30 +149,27 @@ nsStreamLoader::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
return NS_OK;
}
#define BUF_SIZE 1024
NS_METHOD
nsStreamLoader::WriteSegmentFun(nsIInputStream *inStr,
void *closure,
const char *fromSegment,
PRUint32 toOffset,
PRUint32 count,
PRUint32 *writeCount)
{
nsStreamLoader *self = (nsStreamLoader *) closure;
self->mData.Append(fromSegment, count);
*writeCount = count;
return NS_OK;
}
NS_IMETHODIMP
nsStreamLoader::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
nsIInputStream *inStr,
PRUint32 sourceOffset, PRUint32 count)
{
nsresult rv = NS_OK;
char buffer[BUF_SIZE];
PRUint32 len, lenRead;
rv = inStr->Available(&len);
if (NS_FAILED(rv)) return rv;
while (len > 0) {
lenRead = PR_MIN(len, BUF_SIZE);
rv = inStr->Read(buffer, lenRead, &lenRead);
if (NS_FAILED(rv) || lenRead == 0) {
return rv;
}
mData.Append(buffer, lenRead);
len -= lenRead;
}
return rv;
PRUint32 countRead;
return inStr->ReadSegments(WriteSegmentFun, this, count, &countRead);
}

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

@ -59,11 +59,13 @@ public:
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
protected:
static NS_METHOD WriteSegmentFun(nsIInputStream *, void *, const char *,
PRUint32, PRUint32, PRUint32 *);
nsCOMPtr<nsIStreamLoaderObserver> mObserver;
nsCOMPtr<nsISupports> mContext; // the observer's context
nsCString mData;
nsCOMPtr<nsIRequest> mRequest;
/// nsCOMPtr<nsILoadGroup> mLoadGroup;
};
#endif // nsStreamLoader_h__

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

@ -699,7 +699,10 @@ nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
}
#endif
NS_ENSURE_TRUE(mJAR, NS_ERROR_NULL_POINTER);
return mJAR->GetInputStream(mJAREntry, aInputStream);
nsresult rv = mJAR->GetInputStream(mJAREntry, aInputStream);
if (NS_SUCCEEDED(rv))
(*aInputStream)->Available((PRUint32 *) &mContentLength);
return rv;
}
NS_IMETHODIMP