aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-16 14:55:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-16 14:55:49 -0300
commitf8d30826dda6ee8e99200de57a1997734b853db2 (patch)
treed3a24665802f41fe3216714252ed189006f302cd /lvm.c
parent351ccd733298e08c41937c1baf22a68e62bfeca9 (diff)
downloadlua-f8d30826dda6ee8e99200de57a1997734b853db2.tar.gz
lua-f8d30826dda6ee8e99200de57a1997734b853db2.tar.bz2
lua-f8d30826dda6ee8e99200de57a1997734b853db2.zip
New table API for 'set' functions
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/lvm.c b/lvm.c
index ee386847..f5934025 100644
--- a/lvm.c
+++ b/lvm.c
@@ -325,17 +325,16 @@ void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key, StkId val,
325** is no such entry. (The value at 'slot' must be empty, otherwise 325** is no such entry. (The value at 'slot' must be empty, otherwise
326** 'luaV_fastget' would have done the job.) 326** 'luaV_fastget' would have done the job.)
327*/ 327*/
328void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 328void luaV_finishset1 (lua_State *L, const TValue *t, TValue *key,
329 TValue *val, const TValue *slot) { 329 TValue *val, int aux) {
330 int loop; /* counter to avoid infinite loops */ 330 int loop; /* counter to avoid infinite loops */
331 for (loop = 0; loop < MAXTAGLOOP; loop++) { 331 for (loop = 0; loop < MAXTAGLOOP; loop++) {
332 const TValue *tm; /* '__newindex' metamethod */ 332 const TValue *tm; /* '__newindex' metamethod */
333 if (slot != NULL) { /* is 't' a table? */ 333 if (aux != HNOTATABLE) { /* is 't' a table? */
334 Table *h = hvalue(t); /* save 't' table */ 334 Table *h = hvalue(t); /* save 't' table */
335 lua_assert(isempty(slot)); /* slot must be empty */
336 tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */ 335 tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
337 if (tm == NULL) { /* no metamethod? */ 336 if (tm == NULL) { /* no metamethod? */
338 luaH_finishset(L, h, key, slot, val); /* set new value */ 337 luaH_finishset1(L, h, key, val, aux); /* set new value */
339 invalidateTMcache(h); 338 invalidateTMcache(h);
340 luaC_barrierback(L, obj2gco(h), val); 339 luaC_barrierback(L, obj2gco(h), val);
341 return; 340 return;
@@ -353,10 +352,9 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
353 return; 352 return;
354 } 353 }
355 t = tm; /* else repeat assignment over 'tm' */ 354 t = tm; /* else repeat assignment over 'tm' */
356 if (luaV_fastget(L, t, key, slot, luaH_get)) { 355 luaV_fastset1(t, key, val, aux, luaH_set1);
357 luaV_finishfastset(L, t, slot, val); 356 if (aux == HOK)
358 return; /* done */ 357 return; /* done */
359 }
360 /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */ 358 /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */
361 } 359 }
362 luaG_runerror(L, "'__newindex' chain too long; possible loop"); 360 luaG_runerror(L, "'__newindex' chain too long; possible loop");
@@ -1296,59 +1294,61 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1296 vmbreak; 1294 vmbreak;
1297 } 1295 }
1298 vmcase(OP_SETTABUP) { 1296 vmcase(OP_SETTABUP) {
1299 const TValue *slot; 1297 int aux;
1300 TValue *upval = cl->upvals[GETARG_A(i)]->v.p; 1298 TValue *upval = cl->upvals[GETARG_A(i)]->v.p;
1301 TValue *rb = KB(i); 1299 TValue *rb = KB(i);
1302 TValue *rc = RKC(i); 1300 TValue *rc = RKC(i);
1303 TString *key = tsvalue(rb); /* key must be a string */ 1301 TString *key = tsvalue(rb); /* key must be a string */
1304 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) { 1302 luaV_fastset1(upval, key, rc, aux, luaH_setshortstr1);
1305 luaV_finishfastset(L, upval, slot, rc); 1303 if (aux == HOK)
1306 } 1304 luaV_finishfastset1(L, upval, rc);
1307 else 1305 else
1308 Protect(luaV_finishset(L, upval, rb, rc, slot)); 1306 Protect(luaV_finishset1(L, upval, rb, rc, aux));
1309 vmbreak; 1307 vmbreak;
1310 } 1308 }
1311 vmcase(OP_SETTABLE) { 1309 vmcase(OP_SETTABLE) {
1312 StkId ra = RA(i); 1310 StkId ra = RA(i);
1313 const TValue *slot; 1311 int aux;
1314 TValue *rb = vRB(i); /* key (table is in 'ra') */ 1312 TValue *rb = vRB(i); /* key (table is in 'ra') */
1315 TValue *rc = RKC(i); /* value */ 1313 TValue *rc = RKC(i); /* value */
1316 lua_Unsigned n; 1314 if (ttisinteger(rb)) { /* fast track for integers? */
1317 if (ttisinteger(rb) /* fast track for integers? */ 1315 luaV_fastseti1(s2v(ra), ivalue(rb), rc, aux);
1318 ? (cast_void(n = ivalue(rb)), luaV_fastgeti(L, s2v(ra), n, slot)) 1316 }
1319 : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) { 1317 else {
1320 luaV_finishfastset(L, s2v(ra), slot, rc); 1318 luaV_fastset1(s2v(ra), rb, rc, aux, luaH_set1);
1321 } 1319 }
1320 if (aux == HOK)
1321 luaV_finishfastset1(L, s2v(ra), rc);
1322 else 1322 else
1323 Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); 1323 Protect(luaV_finishset1(L, s2v(ra), rb, rc, aux));
1324 vmbreak; 1324 vmbreak;
1325 } 1325 }
1326 vmcase(OP_SETI) { 1326 vmcase(OP_SETI) {
1327 StkId ra = RA(i); 1327 StkId ra = RA(i);
1328 const TValue *slot; 1328 int aux;
1329 int c = GETARG_B(i); 1329 int b = GETARG_B(i);
1330 TValue *rc = RKC(i); 1330 TValue *rc = RKC(i);
1331 if (luaV_fastgeti(L, s2v(ra), c, slot)) { 1331 luaV_fastseti1(s2v(ra), b, rc, aux);
1332 luaV_finishfastset(L, s2v(ra), slot, rc); 1332 if (aux == HOK)
1333 } 1333 luaV_finishfastset1(L, s2v(ra), rc);
1334 else { 1334 else {
1335 TValue key; 1335 TValue key;
1336 setivalue(&key, c); 1336 setivalue(&key, b);
1337 Protect(luaV_finishset(L, s2v(ra), &key, rc, slot)); 1337 Protect(luaV_finishset1(L, s2v(ra), &key, rc, aux));
1338 } 1338 }
1339 vmbreak; 1339 vmbreak;
1340 } 1340 }
1341 vmcase(OP_SETFIELD) { 1341 vmcase(OP_SETFIELD) {
1342 StkId ra = RA(i); 1342 StkId ra = RA(i);
1343 const TValue *slot; 1343 int aux;
1344 TValue *rb = KB(i); 1344 TValue *rb = KB(i);
1345 TValue *rc = RKC(i); 1345 TValue *rc = RKC(i);
1346 TString *key = tsvalue(rb); /* key must be a string */ 1346 TString *key = tsvalue(rb); /* key must be a string */
1347 if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) { 1347 luaV_fastset1(s2v(ra), key, rc, aux, luaH_setshortstr1);
1348 luaV_finishfastset(L, s2v(ra), slot, rc); 1348 if (aux == HOK)
1349 } 1349 luaV_finishfastset1(L, s2v(ra), rc);
1350 else 1350 else
1351 Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); 1351 Protect(luaV_finishset1(L, s2v(ra), rb, rc, aux));
1352 vmbreak; 1352 vmbreak;
1353 } 1353 }
1354 vmcase(OP_NEWTABLE) { 1354 vmcase(OP_NEWTABLE) {