aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-09-30 11:23:33 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-09-30 11:23:33 -0300
commit5dbb87081520de93b54f35969ca84598f70a5673 (patch)
treef2488ba519d10e64b079941c83f32fca384baa10
parentede19c91385e9d30080048e744cf2a363eae968c (diff)
downloadlua-5dbb87081520de93b54f35969ca84598f70a5673.tar.gz
lua-5dbb87081520de93b54f35969ca84598f70a5673.tar.bz2
lua-5dbb87081520de93b54f35969ca84598f70a5673.zip
small optimization for local declarations without initializations
-rw-r--r--lcode.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/lcode.c b/lcode.c
index 0683c23f..c34c9648 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.15 2005/08/17 18:32:09 roberto Exp $ 2** $Id: lcode.c,v 2.16 2005/08/29 20:49:21 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -29,14 +29,17 @@
29 29
30void luaK_nil (FuncState *fs, int from, int n) { 30void luaK_nil (FuncState *fs, int from, int n) {
31 Instruction *previous; 31 Instruction *previous;
32 if (fs->pc > fs->lasttarget && /* no jumps to current position? */ 32 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
33 GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) { 33 if (fs->pc == 0) /* function start? */
34 int pfrom = GETARG_A(*previous); 34 return; /* positions are already clean */
35 int pto = GETARG_B(*previous); 35 if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
36 if (pfrom <= from && from <= pto+1) { /* can connect both? */ 36 int pfrom = GETARG_A(*previous);
37 if (from+n-1 > pto) 37 int pto = GETARG_B(*previous);
38 SETARG_B(*previous, from+n-1); 38 if (pfrom <= from && from <= pto+1) { /* can connect both? */
39 return; 39 if (from+n-1 > pto)
40 SETARG_B(*previous, from+n-1);
41 return;
42 }
40 } 43 }
41 } 44 }
42 luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ 45 luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */