aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-10-25 17:14:14 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-10-25 17:14:14 -0200
commit21aa7e55f2333e57b972aa4ef2c5e2785d609578 (patch)
treebdd6119f0fab0178979202bc5d0afbd6f4410469 /lapi.c
parentfffb6f3814084cddd8a58e81ae1b73ed78ea0953 (diff)
downloadlua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.tar.gz
lua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.tar.bz2
lua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.zip
optimization for array part of a Table
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/lapi.c b/lapi.c
index ea50ea28..e941139a 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.155 2001/10/17 21:12:57 roberto Exp roberto $ 2** $Id: lapi.c,v 1.156 2001/10/17 21:17:45 roberto Exp $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -391,7 +391,7 @@ LUA_API void lua_getglobals (lua_State *L) {
391 391
392LUA_API void lua_newtable (lua_State *L) { 392LUA_API void lua_newtable (lua_State *L) {
393 lua_lock(L); 393 lua_lock(L);
394 sethvalue(L->top, luaH_new(L, 0)); 394 sethvalue(L->top, luaH_new(L, 0, 0));
395 api_incr_top(L); 395 api_incr_top(L);
396 lua_unlock(L); 396 lua_unlock(L);
397} 397}
@@ -647,22 +647,17 @@ LUA_API void lua_unref (lua_State *L, int ref) {
647 647
648LUA_API int lua_next (lua_State *L, int index) { 648LUA_API int lua_next (lua_State *L, int index) {
649 StkId t; 649 StkId t;
650 Node *n;
651 int more; 650 int more;
652 lua_lock(L); 651 lua_lock(L);
653 t = luaA_index(L, index); 652 t = luaA_index(L, index);
654 api_check(L, ttype(t) == LUA_TTABLE); 653 api_check(L, ttype(t) == LUA_TTABLE);
655 n = luaH_next(L, hvalue(t), luaA_index(L, -1)); 654 more = luaH_index(L, hvalue(t), luaA_index(L, -1));
656 if (n) { 655 more = (luaH_nexti(hvalue(t), more, L->top - 1) != -1);
657 setobj(L->top-1, key(n)); 656 if (more) {
658 setobj(L->top, val(n));
659 api_incr_top(L); 657 api_incr_top(L);
660 more = 1;
661 } 658 }
662 else { /* no more elements */ 659 else /* no more elements */
663 L->top -= 1; /* remove key */ 660 L->top -= 1; /* remove key */
664 more = 0;
665 }
666 lua_unlock(L); 661 lua_unlock(L);
667 return more; 662 return more;
668} 663}
@@ -679,9 +674,18 @@ LUA_API int lua_getn (lua_State *L, int index) {
679 if (ttype(value) == LUA_TNUMBER) 674 if (ttype(value) == LUA_TNUMBER)
680 n = cast(int, nvalue(value)); 675 n = cast(int, nvalue(value));
681 else { 676 else {
677 Node *nd;
678 Table *a = hvalue(t);
682 lua_Number max = 0; 679 lua_Number max = 0;
683 int i = hvalue(t)->size; 680 int i;
684 Node *nd = hvalue(t)->node; 681 i = sizearray(a);
682 while (i--) {
683 if (ttype(&a->array[i]) != LUA_TNIL)
684 break;
685 }
686 max = i+1;
687 i = sizenode(a);
688 nd = a->node;
685 while (i--) { 689 while (i--) {
686 if (ttype(key(nd)) == LUA_TNUMBER && 690 if (ttype(key(nd)) == LUA_TNUMBER &&
687 ttype(val(nd)) != LUA_TNIL && 691 ttype(val(nd)) != LUA_TNIL &&
@@ -756,7 +760,7 @@ LUA_API int lua_getweakmode (lua_State *L, int index) {
756LUA_API void lua_setweakmode (lua_State *L, int mode) { 760LUA_API void lua_setweakmode (lua_State *L, int mode) {
757 lua_lock(L); 761 lua_lock(L);
758 api_check(L, ttype(L->top-1) == LUA_TTABLE); 762 api_check(L, ttype(L->top-1) == LUA_TTABLE);
759 hvalue(L->top-1)->weakmode = mode; 763 hvalue(L->top-1)->weakmode = cast(lu_byte, mode);
760 lua_unlock(L); 764 lua_unlock(L);
761} 765}
762 766