From b7efdceee7931dbf3175698c8167e4e6a5dc9a80 Mon Sep 17 00:00:00 2001 From: "reed%reedloden.com" Date: Tue, 22 Sep 2009 06:16:27 +0000 Subject: [PATCH] Bug 516862: Backported a change from dtoa.c upstream made on 2009-03-01. [p=reed r=crowder r=mrbkap a=dveditz] Here is an excerpt from the 'changes' file describing this change: "dtoa.c and gdtoa/gdtoaimp.h and gdtoa/misc.c: reduce Kmax, and use MALLOC and FREE or free for huge blocks, which are possible only in pathological cases, such as dtoa calls in mode 3 with thousands of digits requested, or strtod() calls with thousand of digits. For the latter case, I have an alternate approach that runs much faster and uses less memory, but finding time to get it ready for distribution may take a while." git-svn-id: svn://10.0.0.236/trunk@258450 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/jsdtoa.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mozilla/js/src/jsdtoa.c b/mozilla/js/src/jsdtoa.c index e8bb1858c6c..a750097c816 100644 --- a/mozilla/js/src/jsdtoa.c +++ b/mozilla/js/src/jsdtoa.c @@ -151,7 +151,12 @@ * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) * if memory is available and otherwise does something you deem * appropriate. If MALLOC is undefined, malloc will be invoked - * directly -- and assumed always to succeed. + * directly -- and assumed always to succeed. Similarly, if you + * want something other than the system's free() to be called to + * recycle memory acquired from MALLOC, #define FREE to be the + * name of the alternate routine. (FREE or free is only called in + * pathological cases, e.g., in a dtoa call after a dtoa return in + * mode 3 with thousands of digits requested.) * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making * memory allocations from a private pool of memory when possible. * When used, the private pool is PRIVATE_MEM bytes long: 2000 bytes, @@ -326,7 +331,7 @@ static PRLock *freelist_lock; #define RELEASE_DTOA_LOCK() /*nothing*/ #endif -#define Kmax 15 +#define Kmax 7 struct Bigint { struct Bigint *next; /* Free list link */ @@ -406,7 +411,7 @@ static Bigint *Balloc(int32 k) } #endif - if ((rv = freelist[k]) != NULL) + if (k <= Kmax && (rv = freelist[k]) != NULL) freelist[k] = rv->next; if (rv == NULL) { x = 1 << k; @@ -415,7 +420,7 @@ static Bigint *Balloc(int32 k) #else len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) /sizeof(double); - if (pmem_next - private_mem + len <= PRIVATE_mem) { + if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) { rv = (Bigint*)pmem_next; pmem_next += len; } @@ -434,8 +439,16 @@ static Bigint *Balloc(int32 k) static void Bfree(Bigint *v) { if (v) { - v->next = freelist[v->k]; - freelist[v->k] = v; + if (v->k > Kmax) +#ifdef FREE + FREE((void*)v); +#else + free((void*)v); +#endif + else { + v->next = freelist[v->k]; + freelist[v->k] = v; + } } }