зеркало из https://github.com/mozilla/gecko-dev.git
fixes bug 115129 "stream loader optimizations" r=gagan, sr=brendan,dveditz
This commit is contained in:
Родитель
c739c5639b
Коммит
a2d32b8e4e
|
@ -699,7 +699,10 @@ nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NS_ENSURE_TRUE(mJAR, NS_ERROR_NULL_POINTER);
|
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
|
NS_IMETHODIMP
|
||||||
|
|
|
@ -117,10 +117,18 @@ nsStreamLoader::GetRequest(nsIRequest **aRequest)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
|
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;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,30 +149,27 @@ nsStreamLoader::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
||||||
return NS_OK;
|
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
|
NS_IMETHODIMP
|
||||||
nsStreamLoader::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
|
nsStreamLoader::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
|
||||||
nsIInputStream *inStr,
|
nsIInputStream *inStr,
|
||||||
PRUint32 sourceOffset, PRUint32 count)
|
PRUint32 sourceOffset, PRUint32 count)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
PRUint32 countRead;
|
||||||
char buffer[BUF_SIZE];
|
return inStr->ReadSegments(WriteSegmentFun, this, count, &countRead);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,11 +59,13 @@ public:
|
||||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
static NS_METHOD WriteSegmentFun(nsIInputStream *, void *, const char *,
|
||||||
|
PRUint32, PRUint32, PRUint32 *);
|
||||||
|
|
||||||
nsCOMPtr<nsIStreamLoaderObserver> mObserver;
|
nsCOMPtr<nsIStreamLoaderObserver> mObserver;
|
||||||
nsCOMPtr<nsISupports> mContext; // the observer's context
|
nsCOMPtr<nsISupports> mContext; // the observer's context
|
||||||
nsCString mData;
|
nsCString mData;
|
||||||
nsCOMPtr<nsIRequest> mRequest;
|
nsCOMPtr<nsIRequest> mRequest;
|
||||||
/// nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsStreamLoader_h__
|
#endif // nsStreamLoader_h__
|
||||||
|
|
|
@ -699,7 +699,10 @@ nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NS_ENSURE_TRUE(mJAR, NS_ERROR_NULL_POINTER);
|
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
|
NS_IMETHODIMP
|
||||||
|
|
Загрузка…
Ссылка в новой задаче