summaryrefslogtreecommitdiffstats
path: root/generic/tclCompCmds.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2012-01-30 15:43:34 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2012-01-30 15:43:34 (GMT)
commit84edc366a514da71f1b7e88a4984ea45cf2b6bc2 (patch)
tree941a096e0eb398121c62f012a0fe9145d70e657b /generic/tclCompCmds.c
parent6740ac50e9a65342cacd77245cacb8ad443dda00 (diff)
downloadtcl-84edc366a514da71f1b7e88a4984ea45cf2b6bc2.zip
tcl-84edc366a514da71f1b7e88a4984ea45cf2b6bc2.tar.gz
tcl-84edc366a514da71f1b7e88a4984ea45cf2b6bc2.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.c30
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.
*/