diff options
Diffstat (limited to 'lmem.c')
-rw-r--r-- | lmem.c | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.13 1999/02/26 15:50:10 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.14 1999/03/01 17:49:13 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -22,7 +22,7 @@ | |||
22 | #endif | 22 | #endif |
23 | 23 | ||
24 | 24 | ||
25 | #define MINSIZE 16 /* minimum size for "growing" vectors */ | 25 | #define MINSIZE 8 /* minimum size for "growing" vectors */ |
26 | 26 | ||
27 | 27 | ||
28 | 28 | ||
@@ -39,17 +39,12 @@ static unsigned long power2 (unsigned long n) { | |||
39 | void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, | 39 | void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, |
40 | char *errormsg, unsigned long limit) { | 40 | char *errormsg, unsigned long limit) { |
41 | unsigned long newn = nelems+inc; | 41 | unsigned long newn = nelems+inc; |
42 | if (newn >= limit) lua_error(errormsg); | ||
42 | if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */ | 43 | if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */ |
43 | (nelems > 0 && newn < MINSIZE)) /* or block already is MINSIZE? */ | 44 | (nelems > 0 && newn < MINSIZE)) /* or block already is MINSIZE? */ |
44 | return block; /* do not need to reallocate */ | 45 | return block; /* do not need to reallocate */ |
45 | else { /* it crossed a power of 2 boundary; grow to next power */ | 46 | else /* it crossed a power of 2 boundary; grow to next power */ |
46 | if (newn >= limit) | 47 | return luaM_realloc(block, power2(newn)*size); |
47 | lua_error(errormsg); | ||
48 | newn = power2(newn); | ||
49 | if (newn > limit) | ||
50 | newn = limit; | ||
51 | return luaM_realloc(block, newn*size); | ||
52 | } | ||
53 | } | 48 | } |
54 | 49 | ||
55 | 50 | ||