diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-11 15:57:46 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-11 15:57:46 -0300 |
commit | 7647d5d13d016f114dac4be0b9da62d502eab400 (patch) | |
tree | 7240a95fd732596e658648f6052b29e551a01265 /lvm.h | |
parent | 7184f6343a0074d02f6f0e35654cfa55427710d3 (diff) | |
download | lua-7647d5d13d016f114dac4be0b9da62d502eab400.tar.gz lua-7647d5d13d016f114dac4be0b9da62d502eab400.tar.bz2 lua-7647d5d13d016f114dac4be0b9da62d502eab400.zip |
revamp of fast track for table access (table set uses the same
macros as table get + new macro for integer keys)
Diffstat (limited to 'lvm.h')
-rw-r--r-- | lvm.h | 47 |
1 files changed, 19 insertions, 28 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.h,v 2.40 2016/01/05 16:07:21 roberto Exp roberto $ | 2 | ** $Id: lvm.h,v 2.41 2016/12/22 13:08:50 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 | */ |
@@ -50,10 +50,10 @@ | |||
50 | 50 | ||
51 | /* | 51 | /* |
52 | ** fast track for 'gettable': if 't' is a table and 't[k]' is not nil, | 52 | ** fast track for 'gettable': if 't' is a table and 't[k]' is not nil, |
53 | ** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise, | 53 | ** return 1 with 'slot' pointing to 't[k]' (position of final result). |
54 | ** return 0 (meaning it will have to check metamethod) with 'slot' | 54 | ** Otherwise, return 0 (meaning it will have to check metamethod) |
55 | ** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise). | 55 | ** with 'slot' pointing to a nil 't[k]' (if 't' is a table) or NULL |
56 | ** 'f' is the raw get function to use. | 56 | ** (otherwise). 'f' is the raw get function to use. |
57 | */ | 57 | */ |
58 | #define luaV_fastget(L,t,k,slot,f) \ | 58 | #define luaV_fastget(L,t,k,slot,f) \ |
59 | (!ttistable(t) \ | 59 | (!ttistable(t) \ |
@@ -61,35 +61,26 @@ | |||
61 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ | 61 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ |
62 | !ttisnil(slot))) /* result not nil? */ | 62 | !ttisnil(slot))) /* result not nil? */ |
63 | 63 | ||
64 | |||
64 | /* | 65 | /* |
65 | ** standard implementation for 'gettable' | 66 | ** Special case of 'luaV_fastget' for integers, inlining the fast case |
67 | ** of 'luaH_getint'. | ||
66 | */ | 68 | */ |
67 | #define luaV_gettable(L,t,k,v) { const TValue *slot; \ | 69 | #define luaV_fastgeti(L,t,k,slot) \ |
68 | if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \ | 70 | (!ttistable(t) \ |
69 | else luaV_finishget(L,t,k,v,slot); } | 71 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ |
72 | : (slot = (l_castS2U(k) - 1u < hvalue(t)->sizearray) \ | ||
73 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \ | ||
74 | !ttisnil(slot))) /* result not nil? */ | ||
70 | 75 | ||
71 | 76 | ||
72 | /* | 77 | /* |
73 | ** Fast track for set table. If 't' is a table and 't[k]' is not nil, | 78 | ** Finish a fast set operation (when fast get succeeds). In that case, |
74 | ** call GC barrier, do a raw 't[k]=v', and return true; otherwise, | 79 | ** 'slot' points to the place to put the value. |
75 | ** return false with 'slot' equal to NULL (if 't' is not a table) or | ||
76 | ** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro | ||
77 | ** returns true, there is no need to 'invalidateTMcache', because the | ||
78 | ** call is not creating a new entry. | ||
79 | */ | 80 | */ |
80 | #define luaV_fastset(L,t,k,slot,f,v) \ | 81 | #define luaV_finishfastset(L,t,slot,v) \ |
81 | (!ttistable(t) \ | 82 | (setobj2t(L, cast(TValue *,slot), v), luaC_barrierback(L, hvalue(t), v)) |
82 | ? (slot = NULL, 0) \ | 83 | |
83 | : (slot = f(hvalue(t), k), \ | ||
84 | ttisnil(slot) ? 0 \ | ||
85 | : (luaC_barrierback(L, hvalue(t), v), \ | ||
86 | setobj2t(L, cast(TValue *,slot), v), \ | ||
87 | 1))) | ||
88 | |||
89 | |||
90 | #define luaV_settable(L,t,k,v) { const TValue *slot; \ | ||
91 | if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \ | ||
92 | luaV_finishset(L,t,k,v,slot); } | ||
93 | 84 | ||
94 | 85 | ||
95 | 86 | ||