mirror of https://github.com/rusefi/lua.git
simpler way to count uses
This commit is contained in:
parent
e75a6ae9ee
commit
d6826dbc80
25
ltable.c
25
ltable.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 1.125 2002/12/02 12:06:10 roberto Exp roberto $
|
** $Id: ltable.c,v 1.126 2002/12/04 17:38:31 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -178,21 +178,24 @@ static void computesizes (int nums[], int ntotal, int *narray, int *nhash) {
|
||||||
|
|
||||||
static void numuse (const Table *t, int *narray, int *nhash) {
|
static void numuse (const Table *t, int *narray, int *nhash) {
|
||||||
int nums[MAXBITS+1];
|
int nums[MAXBITS+1];
|
||||||
int i;
|
int i, lg;
|
||||||
int totaluse = 0;
|
int totaluse = 0;
|
||||||
for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* init `nums' */
|
|
||||||
/* count elements in array part */
|
/* count elements in array part */
|
||||||
i = luaO_log2(t->sizearray) + 1; /* number of `slices' */
|
for (i=0, lg=0; lg<=MAXBITS; lg++) { /* for each slice [2^(lg-1) to 2^lg) */
|
||||||
while (i--) { /* for each slice [2^(i-1) to 2^i) */
|
int ttlg = twoto(lg); /* 2^lg */
|
||||||
int to = twoto(i);
|
if (ttlg > t->sizearray) {
|
||||||
int from = to/2;
|
ttlg = t->sizearray;
|
||||||
if (to > t->sizearray) to = t->sizearray;
|
if (i >= ttlg) break;
|
||||||
for (; from < to; from++)
|
}
|
||||||
if (!ttisnil(&t->array[from])) {
|
nums[lg] = 0;
|
||||||
nums[i]++;
|
for (; i<ttlg; i++) {
|
||||||
|
if (!ttisnil(&t->array[i])) {
|
||||||
|
nums[lg]++;
|
||||||
totaluse++;
|
totaluse++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
for (; lg<=MAXBITS; lg++) nums[lg] = 0; /* reset other counts */
|
||||||
*narray = totaluse; /* all previous uses were in array part */
|
*narray = totaluse; /* all previous uses were in array part */
|
||||||
/* count elements in hash part */
|
/* count elements in hash part */
|
||||||
i = sizenode(t);
|
i = sizenode(t);
|
||||||
|
|
Loading…
Reference in New Issue