From 4758113043b6c362a0fdce77715c711332d909dc Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 19 Apr 2011 13:22:13 -0300 Subject: change in opcode OP_LOADNIL: B is used as a counter instead of a register. (Avoids an assignment to R(B), not present in any other instruction.) --- lcode.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lcode.c') diff --git a/lcode.c b/lcode.c index ab2a8295..d2d4b819 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.51 2011/02/01 18:03:10 roberto Exp roberto $ +** $Id: lcode.c,v 2.52 2011/04/07 18:14:12 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -35,19 +35,23 @@ static int isnumeral(expdesc *e) { void luaK_nil (FuncState *fs, int from, int n) { Instruction *previous; + int l = from + n - 1; /* last register to set nil */ if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ previous = &fs->f->code[fs->pc-1]; if (GET_OPCODE(*previous) == OP_LOADNIL) { int pfrom = GETARG_A(*previous); - int pto = GETARG_B(*previous); - if (pfrom <= from && from <= pto+1) { /* can connect both? */ - if (from+n-1 > pto) - SETARG_B(*previous, from+n-1); + int pl = pfrom + GETARG_B(*previous); + if ((pfrom <= from && from <= pl + 1) || + (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */ + if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */ + if (pl > l) l = pl; /* l = max(l, pl) */ + SETARG_A(*previous, from); + SETARG_B(*previous, l - from); return; } - } + } /* else go through */ } - luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ + luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ } -- cgit v1.2.3-55-g6feb