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:
30
ltable.c
30
ltable.c
@@ -752,6 +752,21 @@ const TValue *luaH_getint (Table *t, lua_Integer key) {
|
||||
}
|
||||
|
||||
|
||||
static int finishnodeget (const TValue *val, TValue *res) {
|
||||
if (!ttisnil(val)) {
|
||||
setobj(((lua_State*)NULL), res, val);
|
||||
return HOK; /* success */
|
||||
}
|
||||
else
|
||||
return HNOTFOUND; /* could not get value */
|
||||
}
|
||||
|
||||
|
||||
int luaH_getint1 (Table *t, lua_Integer key, TValue *res) {
|
||||
return finishnodeget(luaH_getint(t, key), res);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** search function for short strings
|
||||
*/
|
||||
@@ -771,6 +786,11 @@ const TValue *luaH_getshortstr (Table *t, TString *key) {
|
||||
}
|
||||
|
||||
|
||||
int luaH_getshortstr1 (Table *t, TString *key, TValue *res) {
|
||||
return finishnodeget(luaH_getshortstr(t, key), res);
|
||||
}
|
||||
|
||||
|
||||
const TValue *luaH_getstr (Table *t, TString *key) {
|
||||
if (key->tt == LUA_VSHRSTR)
|
||||
return luaH_getshortstr(t, key);
|
||||
@@ -782,6 +802,11 @@ const TValue *luaH_getstr (Table *t, TString *key) {
|
||||
}
|
||||
|
||||
|
||||
int luaH_getstr1 (Table *t, TString *key, TValue *res) {
|
||||
return finishnodeget(luaH_getstr(t, key), res);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** main search function
|
||||
*/
|
||||
@@ -802,6 +827,11 @@ const TValue *luaH_get (Table *t, const TValue *key) {
|
||||
}
|
||||
|
||||
|
||||
int luaH_get1 (Table *t, const TValue *key, TValue *res) {
|
||||
return finishnodeget(luaH_get(t, key), res);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Finish a raw "set table" operation, where 'slot' is where the value
|
||||
** should have been (the result of a previous "get table").
|
||||
|
||||
Reference in New Issue
Block a user