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 /lvm.h | |
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 'lvm.h')
-rw-r--r-- | lvm.h | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.h,v 2.34 2014/08/01 17:24:02 roberto Exp roberto $ | 2 | ** $Id: lvm.h,v 2.35 2015/02/20 14:27:53 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -48,13 +48,35 @@ | |||
48 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) | 48 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) |
49 | 49 | ||
50 | 50 | ||
51 | /* | ||
52 | ** fast track for 'gettable': 1 means 'aux' points to resulted value; | ||
53 | ** 0 means 'aux' is metamethod (if 't' is a table) or NULL. 'f' is | ||
54 | ** the raw get function to use. | ||
55 | */ | ||
56 | #define luaV_fastget(L,t,k,aux,f) \ | ||
57 | (!ttistable(t) \ | ||
58 | ? (aux = NULL, 0) /* not a table; 'aux' is NULL and result is 0 */ \ | ||
59 | : (aux = f(hvalue(t), k), /* else, do raw access */ \ | ||
60 | !ttisnil(aux) ? 1 /* result not nil? 'aux' has it */ \ | ||
61 | : (aux = fasttm(L, hvalue(t)->metatable, TM_INDEX), /* get metamethod */\ | ||
62 | aux != NULL ? 0 /* has metamethod? must call it */ \ | ||
63 | : (aux = luaO_nilobject, 1)))) /* else, final result is nil */ | ||
64 | |||
65 | /* | ||
66 | ** standard implementation for 'gettable' | ||
67 | */ | ||
68 | #define luaV_gettable(L,t,k,v) { const TValue *aux; \ | ||
69 | if (luaV_fastget(L,t,k,aux,luaH_get)) { setobj2s(L, v, aux); } \ | ||
70 | else luaV_finishget(L,t,k,v,aux); } | ||
71 | |||
72 | |||
51 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); | 73 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); |
52 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); | 74 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); |
53 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); | 75 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); |
54 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); | 76 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); |
55 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); | 77 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); |
56 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, | 78 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, |
57 | StkId val); | 79 | StkId val, const TValue *tm); |
58 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, | 80 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, |
59 | StkId val); | 81 | StkId val); |
60 | LUAI_FUNC void luaV_finishOp (lua_State *L); | 82 | LUAI_FUNC void luaV_finishOp (lua_State *L); |