diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-07-20 15:24:50 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-07-20 15:24:50 -0300 |
commit | e247c3ada3ff47a1352927e797263137f4e02e0e (patch) | |
tree | 4d2563f59472bdee4c4f58dd87cb1d8eeaf2c1b3 /lapi.c | |
parent | b5dc2f9b0c57fef5f72152973938ff5265366dcd (diff) | |
download | lua-e247c3ada3ff47a1352927e797263137f4e02e0e.tar.gz lua-e247c3ada3ff47a1352927e797263137f4e02e0e.tar.bz2 lua-e247c3ada3ff47a1352927e797263137f4e02e0e.zip |
implementation of fast track for gettable operations
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 48 |
1 files changed, 30 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.249 2015/04/06 12:23:48 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.250 2015/06/18 14:19:52 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -579,16 +579,27 @@ LUA_API int lua_pushthread (lua_State *L) { | |||
579 | */ | 579 | */ |
580 | 580 | ||
581 | 581 | ||
582 | static int auxgetstr (lua_State *L, const TValue *t, const char *k) { | ||
583 | const TValue *aux; | ||
584 | TString *str = luaS_new(L, k); | ||
585 | if (luaV_fastget(L, t, str, aux, luaH_getstr)) { | ||
586 | setobj2s(L, L->top, aux); | ||
587 | api_incr_top(L); | ||
588 | } | ||
589 | else { | ||
590 | setsvalue2s(L, L->top, str); | ||
591 | api_incr_top(L); | ||
592 | luaV_finishget(L, t, L->top - 1, L->top - 1, aux); | ||
593 | } | ||
594 | lua_unlock(L); | ||
595 | return ttnov(L->top - 1); | ||
596 | } | ||
597 | |||
598 | |||
582 | LUA_API int lua_getglobal (lua_State *L, const char *name) { | 599 | LUA_API int lua_getglobal (lua_State *L, const char *name) { |
583 | Table *reg = hvalue(&G(L)->l_registry); | 600 | Table *reg = hvalue(&G(L)->l_registry); |
584 | const TValue *gt; /* global table */ | ||
585 | lua_lock(L); | 601 | lua_lock(L); |
586 | gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | 602 | return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); |
587 | setsvalue2s(L, L->top, luaS_new(L, name)); | ||
588 | api_incr_top(L); | ||
589 | luaV_gettable(L, gt, L->top - 1, L->top - 1); | ||
590 | lua_unlock(L); | ||
591 | return ttnov(L->top - 1); | ||
592 | } | 603 | } |
593 | 604 | ||
594 | 605 | ||
@@ -603,24 +614,25 @@ LUA_API int lua_gettable (lua_State *L, int idx) { | |||
603 | 614 | ||
604 | 615 | ||
605 | LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { | 616 | LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { |
606 | StkId t; | ||
607 | lua_lock(L); | 617 | lua_lock(L); |
608 | t = index2addr(L, idx); | 618 | return auxgetstr(L, index2addr(L, idx), k); |
609 | setsvalue2s(L, L->top, luaS_new(L, k)); | ||
610 | api_incr_top(L); | ||
611 | luaV_gettable(L, t, L->top - 1, L->top - 1); | ||
612 | lua_unlock(L); | ||
613 | return ttnov(L->top - 1); | ||
614 | } | 619 | } |
615 | 620 | ||
616 | 621 | ||
617 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | 622 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { |
618 | StkId t; | 623 | StkId t; |
624 | const TValue *aux; | ||
619 | lua_lock(L); | 625 | lua_lock(L); |
620 | t = index2addr(L, idx); | 626 | t = index2addr(L, idx); |
621 | setivalue(L->top, n); | 627 | if (luaV_fastget(L, t, n, aux, luaH_getint)) { |
622 | api_incr_top(L); | 628 | setobj2s(L, L->top, aux); |
623 | luaV_gettable(L, t, L->top - 1, L->top - 1); | 629 | api_incr_top(L); |
630 | } | ||
631 | else { | ||
632 | setivalue(L->top, n); | ||
633 | api_incr_top(L); | ||
634 | luaV_finishget(L, t, L->top - 1, L->top - 1, aux); | ||
635 | } | ||
624 | lua_unlock(L); | 636 | lua_unlock(L); |
625 | return ttnov(L->top - 1); | 637 | return ttnov(L->top - 1); |
626 | } | 638 | } |