Bug 715770 (part 2) - Don't use nsRecyclingAllocator in libjar. r=taras.

--HG--
extra : rebase_source : 92f39e2d1d62d500e0cdf728b3c95070143015e1
This commit is contained in:
Nicholas Nethercote 2012-01-11 15:20:56 -08:00
Родитель 54daa5bd85
Коммит 5c2594c72d
2 изменённых файлов: 2 добавлений и 46 удалений

Просмотреть файл

@ -51,13 +51,10 @@
#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,
@ -87,8 +84,6 @@ static const mozilla::Module::ContractIDEntry kJARContracts[] = {
// Jar module shutdown hook
static void nsJarShutdown()
{
// Release cached buffers from zlib allocator
delete gZlibAllocator;
NS_IF_RELEASE(gJarHandler);
}

Просмотреть файл

@ -52,7 +52,6 @@
#define READTYPE PRInt32
#include "zlib.h"
#include "nsISupportsUtils.h"
#include "nsRecyclingAllocator.h"
#include "prio.h"
#include "plstr.h"
#include "prlog.h"
@ -66,12 +65,6 @@
#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)
@ -118,46 +111,14 @@ 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;