diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-13 14:08:32 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-13 14:08:32 -0200 |
commit | d6826dbc80f9ce4611a26032274231d46556fe94 (patch) | |
tree | 80891b86483e8049194049a10dd680b1e6374f03 | |
parent | e75a6ae9eee8f990b6c06c533b7b3a2afba6e0f2 (diff) | |
download | lua-d6826dbc80f9ce4611a26032274231d46556fe94.tar.gz lua-d6826dbc80f9ce4611a26032274231d46556fe94.tar.bz2 lua-d6826dbc80f9ce4611a26032274231d46556fe94.zip |
simpler way to count uses
-rw-r--r-- | ltable.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.125 2002/12/02 12:06:10 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.126 2002/12/04 17:38:31 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 | */ |
@@ -178,21 +178,24 @@ static void computesizes (int nums[], int ntotal, int *narray, int *nhash) { | |||
178 | 178 | ||
179 | static void numuse (const Table *t, int *narray, int *nhash) { | 179 | static void numuse (const Table *t, int *narray, int *nhash) { |
180 | int nums[MAXBITS+1]; | 180 | int nums[MAXBITS+1]; |
181 | int i; | 181 | int i, lg; |
182 | int totaluse = 0; | 182 | int totaluse = 0; |
183 | for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* init `nums' */ | ||
184 | /* count elements in array part */ | 183 | /* count elements in array part */ |
185 | i = luaO_log2(t->sizearray) + 1; /* number of `slices' */ | 184 | for (i=0, lg=0; lg<=MAXBITS; lg++) { /* for each slice [2^(lg-1) to 2^lg) */ |
186 | while (i--) { /* for each slice [2^(i-1) to 2^i) */ | 185 | int ttlg = twoto(lg); /* 2^lg */ |
187 | int to = twoto(i); | 186 | if (ttlg > t->sizearray) { |
188 | int from = to/2; | 187 | ttlg = t->sizearray; |
189 | if (to > t->sizearray) to = t->sizearray; | 188 | if (i >= ttlg) break; |
190 | for (; from < to; from++) | 189 | } |
191 | if (!ttisnil(&t->array[from])) { | 190 | nums[lg] = 0; |
192 | nums[i]++; | 191 | for (; i<ttlg; i++) { |
192 | if (!ttisnil(&t->array[i])) { | ||
193 | nums[lg]++; | ||
193 | totaluse++; | 194 | totaluse++; |
194 | } | 195 | } |
196 | } | ||
195 | } | 197 | } |
198 | for (; lg<=MAXBITS; lg++) nums[lg] = 0; /* reset other counts */ | ||
196 | *narray = totaluse; /* all previous uses were in array part */ | 199 | *narray = totaluse; /* all previous uses were in array part */ |
197 | /* count elements in hash part */ | 200 | /* count elements in hash part */ |
198 | i = sizenode(t); | 201 | i = sizenode(t); |