From 84edc366a514da71f1b7e88a4984ea45cf2b6bc2 Mon Sep 17 00:00:00 2001 From: dkf Date: Mon, 30 Jan 2012 15:43:34 +0000 Subject: * 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. --- ChangeLog | 16 +++++++++++----- generic/tclCompCmds.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index e43d7ac..9da588f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,16 @@ +2012-01-30 Donal K. Fellows + + * 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. + 2012-01-26 Don Porter - * generic/tclCmdAH.c: New internal routine TclJoinPath(). - * generic/tclFCmd.c: Refactor all the *Join*Path* routines - * generic/tclFileName.c: to give them more useful interfaces - * generic/tclInt.h: that are easier to manage getting the - * generic/tclPathObj.c: refcounts right. [Bug 3479689] + * generic/tclCmdAH.c: [Bug 3479689]: New internal routine + * generic/tclFCmd.c: TclJoinPath(). Refactor all the + * generic/tclFileName.c: *Join*Path* routines to give them more + * generic/tclInt.h: useful interfaces that are easier to + * generic/tclPathObj.c: manage getting the refcounts right. 2012-01-26 Don Porter 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: 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 returnCode + * simple: 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. */ -- cgit v0.12