Towards a new implementation of arrays
The array part of a table wastes too much space, due to padding. To avoid that, we need to store values in the array as something different from a TValue. Therefore, the API for table access should not assume that any value in a table lives in a *TValue. This commit is the first step to remove that assumption: functions luaH_get*, instead of returning a *TValue where the value lives, receive a *TValue where to put the value being accessed. (We still have to change the luaH_set* functions.)
This commit is contained in:
17
lvm.h
17
lvm.h
@@ -89,6 +89,10 @@ typedef enum {
|
||||
!isempty(slot))) /* result not empty? */
|
||||
|
||||
|
||||
#define luaV_fastget1(t,k,res,f, aux) \
|
||||
(aux = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, res)))
|
||||
|
||||
|
||||
/*
|
||||
** Special case of 'luaV_fastget' for integers, inlining the fast case
|
||||
** of 'luaH_getint'.
|
||||
@@ -100,6 +104,15 @@ typedef enum {
|
||||
? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \
|
||||
!isempty(slot))) /* result not empty? */
|
||||
|
||||
#define luaV_fastgeti1(t,k,val,aux) \
|
||||
if (!ttistable(t)) aux = HNOTATABLE; \
|
||||
else { Table *h = hvalue(t); lua_Unsigned u = l_castS2U(k); \
|
||||
if ((u - 1u < h->alimit)) { \
|
||||
int tag = *getArrTag(h,u); \
|
||||
if (tagisempty(tag)) aux = HNOTFOUND; \
|
||||
else { arr2val(h, u, tag, val); aux = HOK; }} \
|
||||
else { aux = luaH_getint1(h, u, val); }}
|
||||
|
||||
|
||||
/*
|
||||
** Finish a fast set operation (when fast get succeeds). In that case,
|
||||
@@ -125,8 +138,8 @@ LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode);
|
||||
LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p,
|
||||
F2Imod mode);
|
||||
LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode);
|
||||
LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
|
||||
StkId val, const TValue *slot);
|
||||
LUAI_FUNC void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key,
|
||||
StkId val, int aux);
|
||||
LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
|
||||
TValue *val, const TValue *slot);
|
||||
LUAI_FUNC void luaV_finishOp (lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user