summaryrefslogtreecommitdiffstats
path: root/generic/tclCompCmds.c
diff options
context:
space:
mode:
authormig <mig>2013-12-10 11:38:17 (GMT)
committermig <mig>2013-12-10 11:38:17 (GMT)
commit5b08f1d1ef025223ce9bc15d06dbdb88c247822a (patch)
treed8e1081fccdbf33af9b7ef5d71a3c28a89575b30 /generic/tclCompCmds.c
parent49a9c68c2f3e11832b525961440d1d4fb5188d5d (diff)
downloadtcl-5b08f1d1ef025223ce9bc15d06dbdb88c247822a.zip
tcl-5b08f1d1ef025223ce9bc15d06dbdb88c247822a.tar.gz
tcl-5b08f1d1ef025223ce9bc15d06dbdb88c247822a.tar.bz2
new INST_LMAP_COLLECT, speeds up lmap and eliminates the need for a temp var
Diffstat (limited to 'generic/tclCompCmds.c')
-rw-r--r--generic/tclCompCmds.c42
1 files changed, 14 insertions, 28 deletions
diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c
index bdab2ff..cd43cfc 100644
--- a/generic/tclCompCmds.c
+++ b/generic/tclCompCmds.c
@@ -2458,8 +2458,6 @@ CompileEachloopCmd(
ForeachInfo *infoPtr; /* Points to the structure describing this
* foreach command. Stored in a AuxData
* record in the ByteCode. */
- int collectVar = -1; /* Index of temp var holding the result var
- * index. */
Tcl_Token *tokenPtr, *bodyTokenPtr;
int jumpBackOffset, infoIndex, range;
@@ -2575,13 +2573,6 @@ CompileEachloopCmd(
* We will compile the foreach command.
*/
- if (collect == TCL_EACH_COLLECT) {
- collectVar = AnonymousLocal(envPtr);
- if (collectVar < 0) {
- return TCL_ERROR;
- }
- }
-
code = TCL_OK;
/*
@@ -2612,6 +2603,14 @@ CompileEachloopCmd(
infoIndex = TclCreateAuxData(infoPtr, &tclNewForeachInfoType, envPtr);
/*
+ * Create the collecting object, unshared.
+ */
+
+ if (collect == TCL_EACH_COLLECT) {
+ TclEmitInstInt4(INST_LIST, 0, envPtr);
+ }
+
+ /*
* Evaluate each value list and leave it on stack.
*/
@@ -2623,16 +2622,6 @@ CompileEachloopCmd(
}
}
- /*
- * Create temporary variable to capture return values from loop body.
- */
-
- if (collect == TCL_EACH_COLLECT) {
- PushStringLiteral(envPtr, "");
- Emit14Inst( INST_STORE_SCALAR, collectVar, envPtr);
- TclEmitOpcode( INST_POP, envPtr);
- }
-
TclEmitInstInt4(INST_FOREACH_START, infoIndex, envPtr);
/*
@@ -2646,9 +2635,10 @@ CompileEachloopCmd(
ExceptionRangeEnds(envPtr, range);
if (collect == TCL_EACH_COLLECT) {
- Emit14Inst( INST_LAPPEND_SCALAR, collectVar,envPtr);
+ TclEmitOpcode(INST_LMAP_COLLECT, envPtr);
+ } else {
+ TclEmitOpcode( INST_POP, envPtr);
}
- TclEmitOpcode( INST_POP, envPtr);
/*
* Bottom of loop code: assign each loop variable and check whether
@@ -2672,15 +2662,11 @@ CompileEachloopCmd(
infoPtr->loopCtTemp = -jumpBackOffset;
/*
- * The command's result is an empty string if not collecting, or the
- * list of results from evaluating the loop body.
+ * The command's result is an empty string if not collecting. If
+ * collecting, it is automatically left on stack after FOREACH_END.
*/
- if (collect == TCL_EACH_COLLECT) {
- Emit14Inst( INST_LOAD_SCALAR, collectVar, envPtr);
- TclEmitInstInt1(INST_UNSET_SCALAR, 0, envPtr);
- TclEmitInt4( collectVar, envPtr);
- } else {
+ if (collect != TCL_EACH_COLLECT) {
PushStringLiteral(envPtr, "");
}