aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-11-26 18:23:40 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-11-26 18:23:40 -0300
commit65d2294454ab68d164154c7ce05caa50bd97d143 (patch)
tree6cd1a6d00eaf7156d1537d165de26abf82787782 /lstate.c
parent131e3fd814a6e818b412407a222186aab08f3525 (diff)
downloadlua-65d2294454ab68d164154c7ce05caa50bd97d143.tar.gz
lua-65d2294454ab68d164154c7ce05caa50bd97d143.tar.bz2
lua-65d2294454ab68d164154c7ce05caa50bd97d143.zip
Changed access to global table in the registry
The global table is always in the array part of the registry; we can use this fact to make its access slightly more efficient.
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/lstate.c b/lstate.c
index 1c7b8791..1596b51c 100644
--- a/lstate.c
+++ b/lstate.c
@@ -213,17 +213,14 @@ static void freestack (lua_State *L) {
213** Create registry table and its predefined values 213** Create registry table and its predefined values
214*/ 214*/
215static void init_registry (lua_State *L, global_State *g) { 215static void init_registry (lua_State *L, global_State *g) {
216 TValue temp;
217 /* create registry */ 216 /* create registry */
218 Table *registry = luaH_new(L); 217 Table *registry = luaH_new(L);
219 sethvalue(L, &g->l_registry, registry); 218 sethvalue(L, &g->l_registry, registry);
220 luaH_resize(L, registry, LUA_RIDX_LAST, 0); 219 luaH_resize(L, registry, LUA_RIDX_LAST, 0);
221 /* registry[LUA_RIDX_MAINTHREAD] = L */ 220 /* registry[LUA_RIDX_MAINTHREAD] = L */
222 setthvalue(L, &temp, L); /* temp = L */ 221 setthvalue(L, &registry->array[LUA_RIDX_MAINTHREAD - 1], L);
223 luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp); 222 /* registry[LUA_RIDX_GLOBALS] = new table (table of globals) */
224 /* registry[LUA_RIDX_GLOBALS] = table of globals */ 223 sethvalue(L, &registry->array[LUA_RIDX_GLOBALS - 1], luaH_new(L));
225 sethvalue(L, &temp, luaH_new(L)); /* temp = new table (global table) */
226 luaH_setint(L, registry, LUA_RIDX_GLOBALS, &temp);
227} 224}
228 225
229 226