diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-10-13 09:21:51 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-10-13 09:21:51 -0300 |
commit | e9b06c506f8a2cfe09000e99b0b405d385ddb857 (patch) | |
tree | b76d0a0d9134ca8b774ecd4825134c09f65796e7 | |
parent | cd12ab2597cd604eb2c00d73a1c2fea1e6cb472f (diff) | |
download | lua-e9b06c506f8a2cfe09000e99b0b405d385ddb857.tar.gz lua-e9b06c506f8a2cfe09000e99b0b405d385ddb857.tar.bz2 lua-e9b06c506f8a2cfe09000e99b0b405d385ddb857.zip |
small optimization
-rw-r--r-- | lcode.c | 27 |
1 files changed, 12 insertions, 15 deletions
@@ -123,20 +123,22 @@ static int need_value (FuncState *fs, int list) { | |||
123 | } | 123 | } |
124 | 124 | ||
125 | 125 | ||
126 | static void patchtestreg (Instruction *i, int reg) { | 126 | static int patchtestreg (FuncState *fs, int node, int reg) { |
127 | if (reg != NO_REG) | 127 | Instruction *i = getjumpcontrol(fs, node); |
128 | if (GET_OPCODE(*i) != OP_TESTSET) | ||
129 | return 0; /* cannot patch other instructions */ | ||
130 | if (reg != NO_REG && reg != GETARG_B(*i)) | ||
128 | SETARG_A(*i, reg); | 131 | SETARG_A(*i, reg); |
129 | else /* no register to put value; change TESTSET to TEST */ | 132 | else /* no register to put value or register already has the value */ |
130 | *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); | 133 | *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); |
134 | |||
135 | return 1; | ||
131 | } | 136 | } |
132 | 137 | ||
133 | 138 | ||
134 | static void removevalues (FuncState *fs, int list) { | 139 | static void removevalues (FuncState *fs, int list) { |
135 | for (; list != NO_JUMP; list = getjump(fs, list)) { | 140 | for (; list != NO_JUMP; list = getjump(fs, list)) |
136 | Instruction *i = getjumpcontrol(fs, list); | 141 | patchtestreg(fs, list, NO_REG); |
137 | if (GET_OPCODE(*i) == OP_TESTSET) | ||
138 | patchtestreg(i, NO_REG); | ||
139 | } | ||
140 | } | 142 | } |
141 | 143 | ||
142 | 144 | ||
@@ -144,11 +146,8 @@ static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, | |||
144 | int dtarget) { | 146 | int dtarget) { |
145 | while (list != NO_JUMP) { | 147 | while (list != NO_JUMP) { |
146 | int next = getjump(fs, list); | 148 | int next = getjump(fs, list); |
147 | Instruction *i = getjumpcontrol(fs, list); | 149 | if (patchtestreg(fs, list, reg)) |
148 | if (GET_OPCODE(*i) == OP_TESTSET) { | ||
149 | patchtestreg(i, reg); | ||
150 | fixjump(fs, list, vtarget); | 150 | fixjump(fs, list, vtarget); |
151 | } | ||
152 | else | 151 | else |
153 | fixjump(fs, list, dtarget); /* jump to default target */ | 152 | fixjump(fs, list, dtarget); /* jump to default target */ |
154 | list = next; | 153 | list = next; |
@@ -392,9 +391,7 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) { | |||
392 | int p_f = NO_JUMP; /* position of an eventual LOAD false */ | 391 | int p_f = NO_JUMP; /* position of an eventual LOAD false */ |
393 | int p_t = NO_JUMP; /* position of an eventual LOAD true */ | 392 | int p_t = NO_JUMP; /* position of an eventual LOAD true */ |
394 | if (need_value(fs, e->t) || need_value(fs, e->f)) { | 393 | if (need_value(fs, e->t) || need_value(fs, e->f)) { |
395 | int fj = NO_JUMP; /* first jump (over LOAD ops.) */ | 394 | int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); |
396 | if (e->k != VJMP) | ||
397 | fj = luaK_jump(fs); | ||
398 | p_f = code_label(fs, reg, 0, 1); | 395 | p_f = code_label(fs, reg, 0, 1); |
399 | p_t = code_label(fs, reg, 1, 0); | 396 | p_t = code_label(fs, reg, 1, 0); |
400 | luaK_patchtohere(fs, fj); | 397 | luaK_patchtohere(fs, fj); |