diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2012-01-30 15:43:34 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2012-01-30 15:43:34 (GMT) |
commit | cce3ffe950f242015e3280e2c73e50e730020627 (patch) | |
tree | 941a096e0eb398121c62f012a0fe9145d70e657b /generic/tclCompCmds.c | |
parent | 3ce75ba99bee47c73c4297edafde3870246fdc8c (diff) | |
download | tcl-cce3ffe950f242015e3280e2c73e50e730020627.zip tcl-cce3ffe950f242015e3280e2c73e50e730020627.tar.gz tcl-cce3ffe950f242015e3280e2c73e50e730020627.tar.bz2 |
* generic/tclCompCmds.c (TclCompileCatchCmd): Added a more efficient
bytecode generator for the case where 'catch' is used without any
variable arguments; don't capture the result just to discard it.
Diffstat (limited to 'generic/tclCompCmds.c')
-rw-r--r-- | generic/tclCompCmds.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index 69b44ed..1edb56b 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -390,6 +390,32 @@ TclCompileCatchCmd( * simple: <mark> result */ + if (resultIndex == -1) { + /* + * Special case when neither result nor options are being saved. In + * that case, we can skip quite a bit of the command epilogue; all we + * have to do is drop the result and push the return code (and, of + * course, finish the catch context). + */ + + TclEmitOpcode( INST_POP, envPtr); + PushLiteral(envPtr, "0", 1); + TclEmitInstInt1( INST_JUMP1, 3, envPtr); + envPtr->currStackDepth = savedStackDepth; + ExceptionRangeTarget(envPtr, range, catchOffset); + TclEmitOpcode( INST_PUSH_RETURN_CODE, envPtr); + ExceptionRangeEnds(envPtr, range); + TclEmitOpcode( INST_END_CATCH, envPtr); + + /* + * Stack at this point: + * nonsimple: script <mark> returnCode + * simple: <mark> returnCode + */ + + goto dropScriptAtEnd; + } + /* * Emit the "no errors" epilogue: push "0" (TCL_OK) as the catch * result, and jump around the "error case" code. @@ -467,7 +493,9 @@ TclCompileCatchCmd( TclEmitOpcode( INST_POP, envPtr); } - /* + dropScriptAtEnd: + + /* * Stack is now ?script? result. Get rid of the subst'ed script * if it's hanging arond. */ |