summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Sofer <miguel.sofer@gmail.com>2002-06-14 19:31:48 (GMT)
committerMiguel Sofer <miguel.sofer@gmail.com>2002-06-14 19:31:48 (GMT)
commitbe3103c4099dfda4a53affe04992f488d7e8a4fe (patch)
tree057ce72220d95c29b19129566699ccae913f5117
parent715d823e14591cf3069111aaf5e006e00c23c08d (diff)
downloadtcl-be3103c4099dfda4a53affe04992f488d7e8a4fe.zip
tcl-be3103c4099dfda4a53affe04992f488d7e8a4fe.tar.gz
tcl-be3103c4099dfda4a53affe04992f488d7e8a4fe.tar.bz2
BC-engine: runtime peep-hole optimisation of INST_FOREACH
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclExecute.c31
2 files changed, 27 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 53212fe..6d258aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-06-14 Miguel Sofer <msofer@users.sourceforge.net>
+
+ * generic/tclExecute.c (TclExecuteByteCode): runtime peep-hole
+ optimisation of INST_FOREACH - relies on peculiarities of the code
+ produced by the bytecode compiler.
+
2002-06-14 David Gravereaux <davygrvy@pobox.com>
* win/rules.vc: The test for compiler optimizations was in error.
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 9c29d41..37ebc4b 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclExecute.c,v 1.65 2002/06/13 23:10:12 msofer Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.66 2002/06/14 19:31:48 msofer Exp $
*/
#include "tclInt.h"
@@ -3685,7 +3685,13 @@ TclExecuteByteCode(interp, codePtr)
TRACE(("%u => loop iter count temp %d\n",
opnd, iterTmpIndex));
}
- ADJUST_PC(5);
+
+ /*
+ * Remark that the compiler ALWAYS sets INST_FOREACH_STEP4 immediately
+ * after INST_FOREACH_START4 - let us just fall through instead of
+ * ADJUST_PC(5);
+ */
+ pc += 5;
case INST_FOREACH_STEP4:
opnd = TclGetUInt4AtPtr(pc+1);
@@ -3789,18 +3795,23 @@ TclExecuteByteCode(interp, codePtr)
listTmpIndex++;
}
}
-
- /*
- * Push 1 if at least one value list had a remaining element
- * and the loop should continue. Otherwise push 0.
- */
-
- PUSH_OBJECT(Tcl_NewLongObj(continueLoop));
TRACE(("%u => %d lists, iter %d, %s loop\n",
opnd, numLists, iterNum,
(continueLoop? "continue" : "exit")));
+
+ /*
+ * Run-time peep-hole optimisation: the compiler ALWAYS follows
+ * INST_FOREACH_STEP4 with an INST_JUMP_FALSE. We just skip that
+ * instruction and jump direct from here.
+ */
+
+ pc += 5;
+ if (*pc == INST_JUMP_FALSE1) {
+ ADJUST_PC(continueLoop? 2 : TclGetUInt1AtPtr(pc+1));
+ } else {
+ ADJUST_PC(continueLoop? 5 : TclGetUInt4AtPtr(pc+1));
+ }
}
- ADJUST_PC(5);
case INST_BEGIN_CATCH4:
/*