Back out jimm's patch from bug 411579 due to regressions. [a1.9b3=mconnor]
authorreed@reedloden.com
Wed, 30 Jan 2008 15:39:42 -0800
changeset 11085 cba4096619e880e71c6ceb631bb8336709daf691
parent 11084 95dd21360281a72ad7ddcd29bb042ac49973018b
child 11086 f6b000934e3b20894d36ab3854a2d1c285df102c
push idunknown
push userunknown
push dateunknown
bugs411579
milestone1.9b3pre
Back out jimm's patch from bug 411579 due to regressions. [a1.9b3=mconnor]
js/src/xpconnect/loader/mozJSComponentLoader.cpp
modules/libpref/src/nsPrefService.cpp
xpcom/io/nsFastLoadFile.cpp
--- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ -94,23 +94,23 @@ static const char kObserverServiceContra
 /* Some platforms don't have an implementation of PR_MemMap(). */
 /* See bug 318077 for WinCE.                                   */
 #if !defined(XP_BEOS) && !defined(XP_OS2) && !defined(WINCE)
 #define HAVE_PR_MEMMAP
 #endif
 
 /**
  * Buffer sizes for serialization and deserialization of scripts.
- * FIXME: bug #411579 (tune this macro!) Last updated: Jan 2008
+ * These should be tuned at some point.
  */
 #define XPC_SERIALIZATION_BUFFER_SIZE   (64 * 1024)
-#define XPC_DESERIALIZATION_BUFFER_SIZE (12 * 8192)
+#define XPC_DESERIALIZATION_BUFFER_SIZE (8 * 1024)
 
 // Inactivity delay before closing our fastload file stream.
-static const int kFastLoadWriteDelay = 10000;   // 10 seconds
+static const int kFastLoadWriteDelay = 5000;   // 5 seconds
 
 #ifdef PR_LOGGING
 // NSPR_LOG_MODULES=JSComponentLoader:5
 static PRLogModuleInfo *gJSCLLog;
 #endif
 
 #define LOG(args) PR_LOG(gJSCLLog, PR_LOG_DEBUG, args)
 
--- a/modules/libpref/src/nsPrefService.cpp
+++ b/modules/libpref/src/nsPrefService.cpp
@@ -63,16 +63,17 @@
 
 #ifdef MOZ_PROFILESHARING
 #include "nsIProfileSharingSetup.h"
 #include "nsSharedPrefHandler.h"
 #endif
 
 // Definitions
 #define INITIAL_PREF_FILES 10
+#define PREF_READ_BUFFER_SIZE 4096
 
 // Prototypes
 #ifdef MOZ_PROFILESHARING
 static PRBool isSharingEnabled();
 #endif
 
 static nsresult openPrefFile(nsIFile* aFile);
 static nsresult pref_InitInitialObjects(void);
@@ -580,56 +581,45 @@ static PRBool isSharingEnabled()
   }
   return gSharingEnabled;
 }
 #endif
 
 static nsresult openPrefFile(nsIFile* aFile)
 {
   nsCOMPtr<nsIInputStream> inStr;
+  char      readBuf[PREF_READ_BUFFER_SIZE];
 
 #if MOZ_TIMELINE
   {
     nsCAutoString str;
     aFile->GetNativePath(str);
     NS_TIMELINE_MARK_FUNCTION1("load pref file", str.get());
   }
 #endif
 
   nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), aFile);
   if (NS_FAILED(rv)) 
     return rv;        
 
-  PRInt64 fileSize;
-  rv = aFile->GetFileSize(&fileSize);
-  if (NS_FAILED(rv))
-    return rv;
-
-  char *fileBuffer = nsnull;
-  fileBuffer = new char[fileSize];
-  if (fileBuffer == nsnull)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  PRUint32 amtRead = 0;
-  rv = inStr->Read(fileBuffer, fileSize, &amtRead);
-  if (NS_FAILED(rv)) {
-    delete fileBuffer;
-    return rv;
-  }
-
   PrefParseState ps;
   PREF_InitParseState(&ps, PREF_ReaderCallback, NULL);
-
-  if (!PREF_ParseBuf(&ps, fileBuffer, amtRead))
-    rv = NS_ERROR_FILE_CORRUPTED;
+  nsresult rv2 = NS_OK;
+  for (;;) {
+    PRUint32 amtRead = 0;
+    rv = inStr->Read(readBuf, sizeof(readBuf), &amtRead);
+    if (NS_FAILED(rv) || amtRead == 0)
+      break;
 
+    if (!PREF_ParseBuf(&ps, readBuf, amtRead)) {
+      rv2 = NS_ERROR_FILE_CORRUPTED;
+    }
+  }
   PREF_FinalizeParseState(&ps);
-  delete fileBuffer;
-
-  return rv;        
+  return NS_FAILED(rv) ? rv : rv2;        
 }
 
 /*
  * some stuff that gets called from Pref_Init()
  */
 
 static int
 pref_CompareFileNames(nsIFile* aFile1, nsIFile* aFile2, void* /*unused*/)
--- a/xpcom/io/nsFastLoadFile.cpp
+++ b/xpcom/io/nsFastLoadFile.cpp
@@ -625,19 +625,19 @@ nsFastLoadFileReader::SetInputStream(nsI
     nsresult rv = nsBinaryInputStream::SetInputStream(aInputStream);
     mSeekableInput = do_QueryInterface(aInputStream);
     NS_ASSERTION(!mInputStream || mSeekableInput,
                  "FastLoad requires a seekable input stream");
     return rv;
 }
 
 /**
- * FIXME: bug #411579 (tune this macro!) Last updated: Jan 2008
+ * XXX tuneme
  */
-#define MFL_CHECKSUM_BUFSIZE    (6 * 8192)
+#define MFL_CHECKSUM_BUFSIZE    8192
 
 NS_IMETHODIMP
 nsFastLoadFileReader::ComputeChecksum(PRUint32 *aResult)
 {
     nsCOMPtr<nsIInputStream> stream = mInputStream;
     nsCOMPtr<nsISeekableStream> seekable = mSeekableInput;
 
     PRInt64 saveOffset;