mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
Small optimization in 'luaH_psetint'
It is quite common to write to empty but existing cells in the array part of a table, so 'luaH_psetint' checks for the common case that the table doesn't have a newindex metamethod to complete the write.
This commit is contained in:
parent
3e9dbe143d
commit
b34a97a4af
2
ltable.c
2
ltable.c
@ -1001,7 +1001,7 @@ static int rawfinishnodeset (const TValue *slot, TValue *val) {
|
|||||||
int luaH_psetint (Table *t, lua_Integer key, TValue *val) {
|
int luaH_psetint (Table *t, lua_Integer key, TValue *val) {
|
||||||
if (keyinarray(t, key)) {
|
if (keyinarray(t, key)) {
|
||||||
lu_byte *tag = getArrTag(t, key - 1);
|
lu_byte *tag = getArrTag(t, key - 1);
|
||||||
if (!tagisempty(*tag)) {
|
if (!tagisempty(*tag) || checknoTM(t->metatable, TM_NEWINDEX)) {
|
||||||
fval2arr(t, key, tag, val);
|
fval2arr(t, key, tag, val);
|
||||||
return HOK; /* success */
|
return HOK; /* success */
|
||||||
}
|
}
|
||||||
|
7
ltm.h
7
ltm.h
@ -60,11 +60,12 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
#define notm(tm) ttisnil(tm)
|
#define notm(tm) ttisnil(tm)
|
||||||
|
|
||||||
|
#define checknoTM(mt,e) ((mt) == NULL || (mt)->flags & (1u<<(e)))
|
||||||
|
|
||||||
#define gfasttm(g,et,e) ((et) == NULL ? NULL : \
|
#define gfasttm(g,mt,e) \
|
||||||
((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
|
(checknoTM(mt, e) ? NULL : luaT_gettm(mt, e, (g)->tmname[e]))
|
||||||
|
|
||||||
#define fasttm(l,et,e) gfasttm(G(l), et, e)
|
#define fasttm(l,mt,e) gfasttm(G(l), mt, e)
|
||||||
|
|
||||||
#define ttypename(x) luaT_typenames_[(x) + 1]
|
#define ttypename(x) luaT_typenames_[(x) + 1]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user