diff options
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.126 2002/12/04 17:38:31 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.127 2003/02/13 16:08:32 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -160,7 +160,7 @@ static void computesizes (int nums[], int ntotal, int *narray, int *nhash) { | |||
160 | int a = nums[0]; /* number of elements smaller than 2^i */ | 160 | int a = nums[0]; /* number of elements smaller than 2^i */ |
161 | int na = a; /* number of elements to go to array part */ | 161 | int na = a; /* number of elements to go to array part */ |
162 | int n = (na == 0) ? -1 : 0; /* (log of) optimal size for array part */ | 162 | int n = (na == 0) ? -1 : 0; /* (log of) optimal size for array part */ |
163 | for (i = 1; i <= MAXBITS && *narray >= twoto(i-1); i++) { | 163 | for (i = 1; a < *narray && *narray >= twoto(i-1); i++) { |
164 | if (nums[i] > 0) { | 164 | if (nums[i] > 0) { |
165 | a += nums[i]; | 165 | a += nums[i]; |
166 | if (a >= twoto(i-1)) { /* more than half elements in use? */ | 166 | if (a >= twoto(i-1)) { /* more than half elements in use? */ |
@@ -200,8 +200,9 @@ static void numuse (const Table *t, int *narray, int *nhash) { | |||
200 | /* count elements in hash part */ | 200 | /* count elements in hash part */ |
201 | i = sizenode(t); | 201 | i = sizenode(t); |
202 | while (i--) { | 202 | while (i--) { |
203 | if (!ttisnil(val(&t->node[i]))) { | 203 | Node *n = &t->node[i]; |
204 | int k = arrayindex(key(&t->node[i])); | 204 | if (!ttisnil(val(n))) { |
205 | int k = arrayindex(key(n)); | ||
205 | if (k >= 0) { /* is `key' an appropriate array index? */ | 206 | if (k >= 0) { /* is `key' an appropriate array index? */ |
206 | nums[luaO_log2(k-1)+1]++; /* count as such */ | 207 | nums[luaO_log2(k-1)+1]++; /* count as such */ |
207 | (*narray)++; | 208 | (*narray)++; |