Bug 466578. Speed up XBL parsing by increasing the buffer size. r+sr=bzbarsky
authorTaras Glek <tglek@mozilla.com>
Thu, 18 Dec 2008 14:27:43 +1300
changeset 22890 fc47c2c3e3c17bbfe6a3b5706029e8da7f880428
parent 22889 d92586bc82f6049fb8b0538a7e07b23902d976c3
child 22891 51aa9028726792cc751a405080d871024406bb28
push idunknown
push userunknown
push dateunknown
bugs466578
milestone1.9.2a1pre
Bug 466578. Speed up XBL parsing by increasing the buffer size. r+sr=bzbarsky
content/base/src/nsSyncLoadService.cpp
--- a/content/base/src/nsSyncLoadService.cpp
+++ b/content/base/src/nsSyncLoadService.cpp
@@ -453,18 +453,25 @@ nsresult
 nsSyncLoadService::PushSyncStreamToListener(nsIInputStream* aIn,
                                             nsIStreamListener* aListener,
                                             nsIChannel* aChannel)
 {
     // Set up buffering stream
     nsresult rv;
     nsCOMPtr<nsIInputStream> bufferedStream;
     if (!NS_InputStreamIsBuffered(aIn)) {
+        PRInt32 chunkSize;
+        rv = aChannel->GetContentLength(&chunkSize);
+        if (NS_FAILED(rv)) {
+            chunkSize = 4096;
+        }
+        chunkSize = PR_MIN(PR_UINT16_MAX, chunkSize);
+
         rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream), aIn,
-                                       4096);
+                                       chunkSize);
         NS_ENSURE_SUCCESS(rv, rv);
 
         aIn = bufferedStream;
     }
 
     // Load
     aListener->OnStartRequest(aChannel, nsnull);
     PRUint32 sourceOffset = 0;