Bug 715770 (part 2) - Don't use nsRecyclingAllocator in libjar. r=taras.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 11 Jan 2012 15:20:56 -0800
changeset 87047 7ea3311b5e6c2465baf167d3e6dc55998c0ae1fb
parent 87046 ce914679955e8778c312335884d9d97fbbc7321c
child 87048 34572943a3e44c327984dd4d671df580eb521223
child 87054 961442fdd15945f7d1fbe3b4098e87f633de97c5
push idunknown
push userunknown
push dateunknown
reviewerstaras
bugs715770
milestone12.0a1
Bug 715770 (part 2) - Don't use nsRecyclingAllocator in libjar. r=taras.
modules/libjar/nsJARFactory.cpp
modules/libjar/nsZipArchive.cpp
--- a/modules/libjar/nsJARFactory.cpp
+++ b/modules/libjar/nsJARFactory.cpp
@@ -46,23 +46,20 @@
 #include "plstr.h"
 #include "prlog.h"
 
 #include "nsIComponentManager.h"
 #include "nsIServiceManager.h"
 #include "nsCOMPtr.h"
 #include "mozilla/ModuleUtils.h"
 #include "nsIJARFactory.h"
-#include "nsRecyclingAllocator.h"
 #include "nsJARProtocolHandler.h"
 #include "nsJARURI.h"
 #include "nsJAR.h"
 
-extern nsRecyclingAllocator *gZlibAllocator;
-
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJAR)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsZipReaderCache)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsJARProtocolHandler,
                                          nsJARProtocolHandler::GetSingleton)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJARURI)
 
 NS_DEFINE_NAMED_CID(NS_ZIPREADER_CID);
 NS_DEFINE_NAMED_CID(NS_ZIPREADERCACHE_CID);
@@ -82,18 +79,16 @@ static const mozilla::Module::ContractID
     { "@mozilla.org/libjar/zip-reader-cache;1", &kNS_ZIPREADERCACHE_CID },
     { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "jar", &kNS_JARPROTOCOLHANDLER_CID },
     { NULL }
 };
 
 // Jar module shutdown hook
 static void nsJarShutdown()
 {
-    // Release cached buffers from zlib allocator
-    delete gZlibAllocator;
     NS_IF_RELEASE(gJarHandler);
 }
 
 static const mozilla::Module kJARModule = {
     mozilla::Module::kVersion,
     kJARCIDs,
     kJARContracts,
     NULL,
--- a/modules/libjar/nsZipArchive.cpp
+++ b/modules/libjar/nsZipArchive.cpp
@@ -47,36 +47,29 @@
  *
  * The underlying nsZipArchive is NOT thread-safe. Do not pass references
  * or pointers to it across thread boundaries.
  */
 
 #define READTYPE  PRInt32
 #include "zlib.h"
 #include "nsISupportsUtils.h"
-#include "nsRecyclingAllocator.h"
 #include "prio.h"
 #include "plstr.h"
 #include "prlog.h"
 #include "stdlib.h"
 #include "nsWildCard.h"
 #include "nsZipArchive.h"
 #include "nsString.h"
 #include "mozilla/FunctionTimer.h"
 #include "prenv.h"
 #if defined(XP_WIN)
 #include <windows.h>
 #endif
 
-/**
- * Global allocator used with zlib. Destroyed in module shutdown.
- */
-#define NBUCKETS 6
-nsRecyclingAllocator *gZlibAllocator = NULL;
-
 // For placement new used for arena allocations of zip file list
 #include NEW_H
 #define ZIP_ARENABLOCKSIZE (1*1024)
 
 #ifdef XP_UNIX
     #include <sys/types.h>
     #include <sys/stat.h>
     #include <limits.h>
@@ -113,56 +106,24 @@ static const PRUint16 kSyntheticDate = (
 static PRUint16 xtoint(const PRUint8 *ii);
 static PRUint32 xtolong(const PRUint8 *ll);
 static PRUint32 HashName(const char* aName, PRUint16 nameLen);
 #ifdef XP_UNIX
 static nsresult ResolveSymlink(const char *path);
 #endif
 
 //***********************************************************
-// Allocators for use with zlib
-//
-// Use a recycling allocator, for re-use of of the zlib buffers.
 // For every inflation the following allocations are done:
-// zlibAlloc(1, 9520)
-// zlibAlloc(32768, 1)
+// malloc(1 * 9520)
+// malloc(32768 * 1)
 //***********************************************************
 
-static void *
-zlibAlloc(void *opaque, uInt items, uInt size)
-{
-  nsRecyclingAllocator *zallocator = (nsRecyclingAllocator *)opaque;
-  if (zallocator) {
-    return gZlibAllocator->Malloc(items * size);
-  }
-  return malloc(items * size);
-}
-
-static void
-zlibFree(void *opaque, void *ptr)
-{
-  nsRecyclingAllocator *zallocator = (nsRecyclingAllocator *)opaque;
-  if (zallocator)
-    zallocator->Free(ptr);
-  else
-    free(ptr);
-}
-
 nsresult gZlibInit(z_stream *zs)
 {
   memset(zs, 0, sizeof(z_stream));
-  //-- ensure we have our zlib allocator for better performance
-  if (!gZlibAllocator) {
-    gZlibAllocator = new nsRecyclingAllocator(NBUCKETS, NS_DEFAULT_RECYCLE_TIMEOUT, "libjar");
-  }
-  if (gZlibAllocator) {
-    zs->zalloc = zlibAlloc;
-    zs->zfree = zlibFree;
-    zs->opaque = gZlibAllocator;
-  }
   int zerr = inflateInit2(zs, -MAX_WBITS);
   if (zerr != Z_OK) return NS_ERROR_OUT_OF_MEMORY;
 
   return NS_OK;
 }
 
 nsZipHandle::nsZipHandle()
   : mFileData(nsnull)