diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-03-01 14:49:13 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-03-01 14:49:13 -0300 |
commit | ae9fd122fae795d8c23949a9fe77deccb1e5b247 (patch) | |
tree | d0dcb4d2abe7447c8470f879b9d01c9529699dc9 | |
parent | da18ec5d5470c7248296509b8d478b4d4e3f20aa (diff) | |
download | lua-ae9fd122fae795d8c23949a9fe77deccb1e5b247.tar.gz lua-ae9fd122fae795d8c23949a9fe77deccb1e5b247.tar.bz2 lua-ae9fd122fae795d8c23949a9fe77deccb1e5b247.zip |
vector do not need to grow until MINSIZE
-rw-r--r-- | lmem.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.12 1999/02/25 21:07:26 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.13 1999/02/26 15:50:10 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 | */ |
@@ -39,7 +39,10 @@ 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 ^ nelems) > nelems) { /* cross a power of 2 boundary? */ | 42 | if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */ |
43 | (nelems > 0 && newn < MINSIZE)) /* or block already is MINSIZE? */ | ||
44 | return block; /* do not need to reallocate */ | ||
45 | else { /* it crossed a power of 2 boundary; grow to next power */ | ||
43 | if (newn >= limit) | 46 | if (newn >= limit) |
44 | lua_error(errormsg); | 47 | lua_error(errormsg); |
45 | newn = power2(newn); | 48 | newn = power2(newn); |
@@ -47,8 +50,6 @@ void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, | |||
47 | newn = limit; | 50 | newn = limit; |
48 | return luaM_realloc(block, newn*size); | 51 | return luaM_realloc(block, newn*size); |
49 | } | 52 | } |
50 | else | ||
51 | return block; | ||
52 | } | 53 | } |
53 | 54 | ||
54 | 55 | ||