From 21cc17196d4c5b38a507570be2e54a7367800686 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 2 Apr 2015 14:22:14 -0400 Subject: [PATCH] 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. --- modules/libjar/zipwriter/nsDeflateConverter.cpp | 10 +++++----- modules/libjar/zipwriter/nsZipDataStream.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/libjar/zipwriter/nsDeflateConverter.cpp b/modules/libjar/zipwriter/nsDeflateConverter.cpp index 77eb825db2dd..0583b68cef62 100644 --- a/modules/libjar/zipwriter/nsDeflateConverter.cpp +++ b/modules/libjar/zipwriter/nsDeflateConverter.cpp @@ -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 stream = - do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv); + MOZ_ASSERT(bytesToWrite <= INT32_MAX); + nsCOMPtr 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); diff --git a/modules/libjar/zipwriter/nsZipDataStream.cpp b/modules/libjar/zipwriter/nsZipDataStream.cpp index f7fcb622a58f..d885c7197b2a 100644 --- a/modules/libjar/zipwriter/nsZipDataStream.cpp +++ b/modules/libjar/zipwriter/nsZipDataStream.cpp @@ -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(aBuffer), aCount); - nsresult rv; - nsCOMPtr stream = - do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv); + MOZ_ASSERT(aCount <= INT32_MAX); + nsCOMPtr 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;