diff options
| -rw-r--r-- | ltable.c | 18 |
1 files changed, 9 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.39 2009/03/30 18:38:24 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.40 2009/04/17 14:40:13 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 | */ |
| @@ -308,7 +308,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { | |||
| 308 | /* re-insert elements from vanishing slice */ | 308 | /* re-insert elements from vanishing slice */ |
| 309 | for (i=nasize; i<oldasize; i++) { | 309 | for (i=nasize; i<oldasize; i++) { |
| 310 | if (!ttisnil(&t->array[i])) | 310 | if (!ttisnil(&t->array[i])) |
| 311 | setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]); | 311 | setobjt2t(L, luaH_setint(L, t, i+1), &t->array[i]); |
| 312 | } | 312 | } |
| 313 | /* shrink array */ | 313 | /* shrink array */ |
| 314 | luaM_reallocvector(L, t->array, oldasize, nasize, TValue); | 314 | luaM_reallocvector(L, t->array, oldasize, nasize, TValue); |
| @@ -429,7 +429,7 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { | |||
| 429 | /* | 429 | /* |
| 430 | ** search function for integers | 430 | ** search function for integers |
| 431 | */ | 431 | */ |
| 432 | const TValue *luaH_getnum (Table *t, int key) { | 432 | const TValue *luaH_getint (Table *t, int key) { |
| 433 | /* (1 <= key && key <= t->sizearray) */ | 433 | /* (1 <= key && key <= t->sizearray) */ |
| 434 | if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) | 434 | if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) |
| 435 | return &t->array[key-1]; | 435 | return &t->array[key-1]; |
| @@ -472,7 +472,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
| 472 | lua_Number n = nvalue(key); | 472 | lua_Number n = nvalue(key); |
| 473 | lua_number2int(k, n); | 473 | lua_number2int(k, n); |
| 474 | if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ | 474 | if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ |
| 475 | return luaH_getnum(t, k); /* use specialized version */ | 475 | return luaH_getint(t, k); /* use specialized version */ |
| 476 | /* else go through */ | 476 | /* else go through */ |
| 477 | } | 477 | } |
| 478 | default: { | 478 | default: { |
| @@ -502,8 +502,8 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { | |||
| 502 | } | 502 | } |
| 503 | 503 | ||
| 504 | 504 | ||
| 505 | TValue *luaH_setnum (lua_State *L, Table *t, int key) { | 505 | TValue *luaH_setint (lua_State *L, Table *t, int key) { |
| 506 | const TValue *p = luaH_getnum(t, key); | 506 | const TValue *p = luaH_getint(t, key); |
| 507 | if (p != luaO_nilobject) | 507 | if (p != luaO_nilobject) |
| 508 | return cast(TValue *, p); | 508 | return cast(TValue *, p); |
| 509 | else { | 509 | else { |
| @@ -530,20 +530,20 @@ static int unbound_search (Table *t, unsigned int j) { | |||
| 530 | unsigned int i = j; /* i is zero or a present index */ | 530 | unsigned int i = j; /* i is zero or a present index */ |
| 531 | j++; | 531 | j++; |
| 532 | /* find `i' and `j' such that i is present and j is not */ | 532 | /* find `i' and `j' such that i is present and j is not */ |
| 533 | while (!ttisnil(luaH_getnum(t, j))) { | 533 | while (!ttisnil(luaH_getint(t, j))) { |
| 534 | i = j; | 534 | i = j; |
| 535 | j *= 2; | 535 | j *= 2; |
| 536 | if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ | 536 | if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ |
| 537 | /* table was built with bad purposes: resort to linear search */ | 537 | /* table was built with bad purposes: resort to linear search */ |
| 538 | i = 1; | 538 | i = 1; |
| 539 | while (!ttisnil(luaH_getnum(t, i))) i++; | 539 | while (!ttisnil(luaH_getint(t, i))) i++; |
| 540 | return i - 1; | 540 | return i - 1; |
| 541 | } | 541 | } |
| 542 | } | 542 | } |
| 543 | /* now do a binary search between them */ | 543 | /* now do a binary search between them */ |
| 544 | while (j - i > 1) { | 544 | while (j - i > 1) { |
| 545 | unsigned int m = (i+j)/2; | 545 | unsigned int m = (i+j)/2; |
| 546 | if (ttisnil(luaH_getnum(t, m))) j = m; | 546 | if (ttisnil(luaH_getint(t, m))) j = m; |
| 547 | else i = m; | 547 | else i = m; |
| 548 | } | 548 | } |
| 549 | return i; | 549 | return i; |
