From 71500874b393cf7e4a8528218307492dd88d18b7 Mon Sep 17 00:00:00 2001
From: dkf <donal.k.fellows@manchester.ac.uk>
Date: Tue, 18 Dec 2012 09:37:42 +0000
Subject: Generate better code for the common case of subst-ed variables where
 the variable is a simple scalar or an array with a simple literal element
 name.

---
 generic/tclCompCmdsSZ.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c
index 9c93fb2..71a1dfc 100644
--- a/generic/tclCompCmdsSZ.c
+++ b/generic/tclCompCmdsSZ.c
@@ -836,6 +836,21 @@ TclSubstCompile(
 	    TclEmitPush(literal, envPtr);
 	    count++;
 	    continue;
+	case TCL_TOKEN_VARIABLE:
+	    /*
+	     * Simple variable access; can only generate TCL_OK or TCL_ERROR
+	     * so no need to generate elaborate exception-management code.
+	     */
+
+	    if (tokenPtr->numComponents == 1 || (tokenPtr->numComponents == 2
+		    && tokenPtr[2].type == TCL_TOKEN_TEXT)) {
+		envPtr->line = bline;
+		TclCompileVarSubst(interp, tokenPtr, envPtr);
+		bline = envPtr->line;
+		count++;
+		continue;
+	    }
+	    break;
 	}
 
 	while (count > 255) {
-- 
cgit v0.12


From ee58f2d325a281f03cf6669e8d7ae2c377a5af2d Mon Sep 17 00:00:00 2001
From: dkf <donal.k.fellows@manchester.ac.uk>
Date: Tue, 18 Dec 2012 10:21:34 +0000
Subject: Better version that can handle simple composite array keys as well.
 As long as they are free of command substitutions, we can still safely omit
 the exception processor code.

---
 generic/tclCompCmdsSZ.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c
index 71a1dfc..7bead0d 100644
--- a/generic/tclCompCmdsSZ.c
+++ b/generic/tclCompCmdsSZ.c
@@ -838,19 +838,32 @@ TclSubstCompile(
 	    continue;
 	case TCL_TOKEN_VARIABLE:
 	    /*
-	     * Simple variable access; can only generate TCL_OK or TCL_ERROR
-	     * so no need to generate elaborate exception-management code.
+	     * Check for simple variable access; see if we can only generate
+	     * TCL_OK or TCL_ERROR from the substituted variable read; if so,
+	     * there is no need to generate elaborate exception-management
+	     * code. Note that the first component of TCL_TOKEN_VARIABLE is
+	     * always TCL_TOKEN_TEXT...
 	     */
 
-	    if (tokenPtr->numComponents == 1 || (tokenPtr->numComponents == 2
-		    && tokenPtr[2].type == TCL_TOKEN_TEXT)) {
-		envPtr->line = bline;
-		TclCompileVarSubst(interp, tokenPtr, envPtr);
-		bline = envPtr->line;
-		count++;
-		continue;
+	    if (tokenPtr->numComponents > 1) {
+		int i, foundCommand = 0;
+
+		for (i=2 ; i<=tokenPtr->numComponents ; i++) {
+		    if (tokenPtr[i].type == TCL_TOKEN_COMMAND) {
+			foundCommand = 1;
+			break;
+		    }
+		}
+		if (foundCommand) {
+		    break;
+		}
 	    }
-	    break;
+
+	    envPtr->line = bline;
+	    TclCompileVarSubst(interp, tokenPtr, envPtr);
+	    bline = envPtr->line;
+	    count++;
+	    continue;
 	}
 
 	while (count > 255) {
-- 
cgit v0.12