issue #60 improve parsing of table get access with short strings

pull/81/head
Dibyendu Majumdar 9 years ago
parent 085f035917
commit 7db1eee15b

@ -422,6 +422,18 @@ void luaK_setoneret (FuncState *fs, expdesc *e) {
}
}
/**
* Is the operand a reference to a short string constant?
*/
static int isshortstr(FuncState *fs, int kk) {
if (ISK(kk)) {
Proto *f = fs->f;
kk = INDEXK(kk);
lua_assert(kk >= 0 && kk < f->sizek);
return ttisshrstring(&f->k[kk]);
}
return 0;
}
void luaK_dischargevars (FuncState *fs, expdesc *e) {
switch (e->k) {
@ -441,12 +453,14 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
freereg(fs, e->u.ind.idx);
if (e->u.ind.vt == VLOCAL) { /* 't' is in a register? */
freereg(fs, e->u.ind.t);
/* TODO we should do this for upvalues too */
/* table access - set specialized op codes if array types are detected */
if (e->ravi_type == RAVI_TARRAYFLT && e->u.ind.key_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_AF;
else if (e->ravi_type == RAVI_TARRAYINT && e->u.ind.key_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_AI;
else if (e->ravi_type == RAVI_TTABLE && e->u.ind.key_type == RAVI_TSTRING)
/* Check that we have a short string constant */
else if (e->ravi_type == RAVI_TTABLE && e->u.ind.key_type == RAVI_TSTRING && isshortstr(fs, e->u.ind.idx))
op = OP_RAVI_GETTABLE_S;
else if (e->ravi_type == RAVI_TTABLE && e->u.ind.key_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_I;

@ -886,17 +886,10 @@ newframe: /* reentry point when frame changes (call/return) */
break;
}
case OP_RAVI_GETTABLE_S: {
if (ISK(GETARG_C(i))) {
TValue *kv = k + INDEXK(GETARG_C(i));
TString *key = tsvalue(kv);
if (key->tt == LUA_TSHRSTR) {
const TValue *v = luaH_getstr(hvalue(RB(i)), key);
setobj2s(L, ra, v);
}
else
goto l_gettable;
} else
goto l_gettable;
TValue *kv = k + INDEXK(GETARG_C(i));
TString *key = tsvalue(kv);
const TValue *v = luaH_getstr(hvalue(RB(i)), key);
setobj2s(L, ra, v);
/*
if (ISK(GETARG_C(i))) {
TValue *kv = k + INDEXK(GETARG_C(i));

@ -1550,17 +1550,11 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p,
case OP_RAVI_GETTABLE_S: {
int C = GETARG_C(i);
int B = GETARG_B(i);
if (ISK(C)) {
TValue *kv = k + INDEXK(C);
TString *key = tsvalue(kv);
if (key->tt == LUA_TSHRSTR) {
emit_GETTABLE_S(def, A, B, C, pc, key);
} else {
emit_GETTABLE(def, A, B, C, pc);
}
} else {
emit_GETTABLE(def, A, B, C, pc);
}
lua_assert(ISK(C));
TValue *kv = k + INDEXK(C);
TString *key = tsvalue(kv);
lua_assert(key->tt == LUA_TSHRSTR);
emit_GETTABLE_S(def, A, B, C, pc, key);
} break;
case OP_RAVI_GETTABLE_I: {
int B = GETARG_B(i);

Loading…
Cancel
Save