diff options
author | Miguel Sofer <miguel.sofer@gmail.com> | 2004-05-12 17:43:52 (GMT) |
---|---|---|
committer | Miguel Sofer <miguel.sofer@gmail.com> | 2004-05-12 17:43:52 (GMT) |
commit | 200415876026090ba976a55f11c319630f0ef9ae (patch) | |
tree | a05f9e6a5498d422911ad35005a0f3a51b875ceb /generic/tclCompile.c | |
parent | 0d8310f9be1577fb211b01fbbe020ea6621fc1e5 (diff) | |
download | tcl-200415876026090ba976a55f11c319630f0ef9ae.zip tcl-200415876026090ba976a55f11c319630f0ef9ae.tar.gz tcl-200415876026090ba976a55f11c319630f0ef9ae.tar.bz2 |
Optimisations for INST_START_CMD [Bug 926164].
* generic/tclCompile.c (TclCompileScript): avoid emitting
INST_START_CMD as the first instruction in a bytecoded Tcl_Obj. It
is not needed, as the checks are done before calling TEBC.
* generic/tclExecute.c (TclExecuteByteCode): runtime peephole
optimisation: check at INST_POP if the next instruction is
INST_START_CMD, in which case we fall through.
Diffstat (limited to 'generic/tclCompile.c')
-rw-r--r-- | generic/tclCompile.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/generic/tclCompile.c b/generic/tclCompile.c index e75a5a4..c918c5d 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.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: tclCompile.c,v 1.64 2004/05/04 02:44:23 msofer Exp $ + * RCS: @(#) $Id: tclCompile.c,v 1.65 2004/05/12 17:43:54 msofer Exp $ */ #include "tclInt.h" @@ -1057,28 +1057,36 @@ TclCompileScript(interp, script, numBytes, envPtr) && !(iPtr->flags & DONT_COMPILE_CMDS_INLINE)) { int savedNumCmds = envPtr->numCommands; unsigned int savedCodeNext = - envPtr->codeNext - envPtr->codeStart; + envPtr->codeNext - envPtr->codeStart; /* * Mark the start of the command; the proper - * bytecode length will be updated later. + * bytecode length will be updated later. There + * is no need to do this for the first command + * in the compile env, as the check is done before + * calling TclExecuteByteCode(). Remark that we + * are compiling the first cmd in the environment + * exactly when (savedCodeNext == 0) */ - - TclEmitInstInt4(INST_START_CMD, 0, envPtr); + + if (savedCodeNext != 0) { + TclEmitInstInt4(INST_START_CMD, 0, envPtr); + } code = (*(cmdPtr->compileProc))(interp, &parse, envPtr); if (code == TCL_OK) { - /* - * Fix the bytecode length. - */ - unsigned char *fixPtr = envPtr->codeStart + savedCodeNext + 1; - unsigned int fixLen = envPtr->codeNext - envPtr->codeStart - - savedCodeNext; - - TclStoreInt4AtPtr(fixLen, fixPtr); + if (savedCodeNext != 0) { + /* + * Fix the bytecode length. + */ + unsigned char *fixPtr = envPtr->codeStart + savedCodeNext + 1; + unsigned int fixLen = envPtr->codeNext - envPtr->codeStart + - savedCodeNext; + TclStoreInt4AtPtr(fixLen, fixPtr); + } goto finishCommand; } else if (code == TCL_OUT_LINE_COMPILE) { /* |