Bug 1153259 - use NS_NewByteInputStream in zipwriter to reduce do_CreateInstance overhead; r=aklotz

Profiling startup shows that we have several thousand calls to:

  do_CreateInstance("@mozilla.org/io/string-input-stream;1")

and virtually all of them are located in the zipwriter code.  We can
create string input streams much more directly with
NS_NewByteInputStream, which avoids a lot of overhead associated with
do_CreateInstance.
This commit is contained in:
Nathan Froyd 2015-04-02 14:22:14 -04:00
parent 2cbd0c71c8
commit 21cc17196d
2 changed files with 10 additions and 10 deletions

View File

@ -5,7 +5,7 @@
#include "StreamFunctions.h"
#include "nsDeflateConverter.h"
#include "nsIStringStream.h"
#include "nsStringStream.h"
#include "nsIInputStreamPump.h"
#include "nsComponentManagerUtils.h"
#include "nsMemory.h"
@ -180,12 +180,12 @@ nsresult nsDeflateConverter::PushAvailableData(nsIRequest *aRequest,
if (bytesToWrite == 0)
return NS_OK;
nsresult rv;
nsCOMPtr<nsIStringInputStream> stream =
do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
MOZ_ASSERT(bytesToWrite <= INT32_MAX);
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
(char*)mWriteBuffer, bytesToWrite);
NS_ENSURE_SUCCESS(rv, rv);
stream->ShareData((char*)mWriteBuffer, bytesToWrite);
rv = mListener->OnDataAvailable(aRequest, mContext, stream, mOffset,
bytesToWrite);

View File

@ -5,7 +5,7 @@
#include "StreamFunctions.h"
#include "nsZipDataStream.h"
#include "nsIStringStream.h"
#include "nsStringStream.h"
#include "nsISeekableStream.h"
#include "nsDeflateConverter.h"
#include "nsNetUtil.h"
@ -138,12 +138,12 @@ nsresult nsZipDataStream::ProcessData(nsIRequest *aRequest,
reinterpret_cast<const unsigned char*>(aBuffer),
aCount);
nsresult rv;
nsCOMPtr<nsIStringInputStream> stream =
do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
MOZ_ASSERT(aCount <= INT32_MAX);
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
aBuffer, aCount);
NS_ENSURE_SUCCESS(rv, rv);
stream->ShareData(aBuffer, aCount);
rv = mOutput->OnDataAvailable(aRequest, aContext, stream, aOffset, aCount);
mHeader->mUSize += aCount;