luaH_[gs]etnum renamed to luaH_[gs]etint (as they only accept integers,
not generic numbers).
This commit is contained in:
18
ltable.c
18
ltable.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 2.39 2009/03/30 18:38:24 roberto Exp roberto $
|
** $Id: ltable.c,v 2.40 2009/04/17 14:40:13 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -308,7 +308,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
|
|||||||
/* re-insert elements from vanishing slice */
|
/* re-insert elements from vanishing slice */
|
||||||
for (i=nasize; i<oldasize; i++) {
|
for (i=nasize; i<oldasize; i++) {
|
||||||
if (!ttisnil(&t->array[i]))
|
if (!ttisnil(&t->array[i]))
|
||||||
setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]);
|
setobjt2t(L, luaH_setint(L, t, i+1), &t->array[i]);
|
||||||
}
|
}
|
||||||
/* shrink array */
|
/* shrink array */
|
||||||
luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
|
luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
|
||||||
@@ -429,7 +429,7 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
|
|||||||
/*
|
/*
|
||||||
** search function for integers
|
** search function for integers
|
||||||
*/
|
*/
|
||||||
const TValue *luaH_getnum (Table *t, int key) {
|
const TValue *luaH_getint (Table *t, int key) {
|
||||||
/* (1 <= key && key <= t->sizearray) */
|
/* (1 <= key && key <= t->sizearray) */
|
||||||
if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
|
if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
|
||||||
return &t->array[key-1];
|
return &t->array[key-1];
|
||||||
@@ -472,7 +472,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
|
|||||||
lua_Number n = nvalue(key);
|
lua_Number n = nvalue(key);
|
||||||
lua_number2int(k, n);
|
lua_number2int(k, n);
|
||||||
if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
|
if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
|
||||||
return luaH_getnum(t, k); /* use specialized version */
|
return luaH_getint(t, k); /* use specialized version */
|
||||||
/* else go through */
|
/* else go through */
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -502,8 +502,8 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TValue *luaH_setnum (lua_State *L, Table *t, int key) {
|
TValue *luaH_setint (lua_State *L, Table *t, int key) {
|
||||||
const TValue *p = luaH_getnum(t, key);
|
const TValue *p = luaH_getint(t, key);
|
||||||
if (p != luaO_nilobject)
|
if (p != luaO_nilobject)
|
||||||
return cast(TValue *, p);
|
return cast(TValue *, p);
|
||||||
else {
|
else {
|
||||||
@@ -530,20 +530,20 @@ static int unbound_search (Table *t, unsigned int j) {
|
|||||||
unsigned int i = j; /* i is zero or a present index */
|
unsigned int i = j; /* i is zero or a present index */
|
||||||
j++;
|
j++;
|
||||||
/* find `i' and `j' such that i is present and j is not */
|
/* find `i' and `j' such that i is present and j is not */
|
||||||
while (!ttisnil(luaH_getnum(t, j))) {
|
while (!ttisnil(luaH_getint(t, j))) {
|
||||||
i = j;
|
i = j;
|
||||||
j *= 2;
|
j *= 2;
|
||||||
if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
|
if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
|
||||||
/* table was built with bad purposes: resort to linear search */
|
/* table was built with bad purposes: resort to linear search */
|
||||||
i = 1;
|
i = 1;
|
||||||
while (!ttisnil(luaH_getnum(t, i))) i++;
|
while (!ttisnil(luaH_getint(t, i))) i++;
|
||||||
return i - 1;
|
return i - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* now do a binary search between them */
|
/* now do a binary search between them */
|
||||||
while (j - i > 1) {
|
while (j - i > 1) {
|
||||||
unsigned int m = (i+j)/2;
|
unsigned int m = (i+j)/2;
|
||||||
if (ttisnil(luaH_getnum(t, m))) j = m;
|
if (ttisnil(luaH_getint(t, m))) j = m;
|
||||||
else i = m;
|
else i = m;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
|
|||||||
Reference in New Issue
Block a user