summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdAH.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclCmdAH.c')
-rw-r--r--generic/tclCmdAH.c58
1 files changed, 11 insertions, 47 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 333946a..a10646c 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -45,7 +45,7 @@ static int EncodingDirsObjCmd(ClientData dummy,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
static inline int ForeachAssignments(Tcl_Interp *interp,
- struct ForeachState *statePtr, int collect);
+ struct ForeachState *statePtr);
static inline void ForeachCleanup(Tcl_Interp *interp,
struct ForeachState *statePtr);
static int GetStatBuf(Tcl_Interp *interp, Tcl_Obj *pathPtr,
@@ -2619,26 +2619,6 @@ TclNRMapeachCmd(
}
int
-Tcl_ForeachaObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *const objv[]) /* Argument objects. */
-{
- return Tcl_NRCallObjProc(interp, TclNRForeachaCmd, dummy, objc, objv);
-}
-
-int
-TclNRForeachaCmd(
- ClientData dummy,
- Tcl_Interp *interp,
- int objc,
- Tcl_Obj *const objv[])
-{
- return TclNREachloopCmd(dummy, interp, objc, objv, TCL_EACH_ACCUM);
-}
-
-int
TclNREachloopCmd(
ClientData dummy,
Tcl_Interp *interp,
@@ -2720,13 +2700,9 @@ TclNREachloopCmd(
TclListObjGetElements(NULL, statePtr->aCopyList[i],
&statePtr->argcList[i], &statePtr->argvList[i]);
- j = (i == 0) && (collect == TCL_EACH_ACCUM); /* Accumulator present? */
- /* If accumulator is only var in list, then we iterate j=1 times */
- if (statePtr->varcList[i] > j) {
- /* We need listLen/numVars round up = ((listLen+numVars-1)/numVars)
- * When accum is present we need (listLen-1)/(numVars-1) round up */
- j = (statePtr->argcList[i] - j + statePtr->varcList[i] - j - 1)
- / (statePtr->varcList[i] - j);
+ j = statePtr->argcList[i] / statePtr->varcList[i];
+ if ((statePtr->argcList[i] % statePtr->varcList[i]) != 0) {
+ j++;
}
if (j > statePtr->maxj) {
statePtr->maxj = j;
@@ -2739,7 +2715,7 @@ TclNREachloopCmd(
*/
if (statePtr->maxj > 0) {
- result = ForeachAssignments(interp, statePtr, collect);
+ result = ForeachAssignments(interp, statePtr);
if (result == TCL_ERROR) {
goto done;
}
@@ -2803,7 +2779,7 @@ ForeachLoopStep(
*/
if (statePtr->maxj > ++statePtr->j) {
- result = ForeachAssignments(interp, statePtr, collect);
+ result = ForeachAssignments(interp, statePtr);
if (result == TCL_ERROR) {
goto done;
}
@@ -2816,18 +2792,9 @@ ForeachLoopStep(
/*
* We're done. Tidy up our work space and finish off.
*/
-finish:
- if (collect == TCL_EACH_ACCUM) {
- Tcl_Obj* valueObj = Tcl_ObjGetVar2(interp, statePtr->varvList[0][0],
- NULL, TCL_LEAVE_ERR_MSG);
- if (valueObj == NULL) {
- goto done;
- }
- Tcl_SetObjResult(interp, valueObj);
- } else {
- Tcl_SetObjResult(interp, statePtr->resultList);
- statePtr->resultList = NULL; /* Don't clean it up */
- }
+ finish:
+ Tcl_SetObjResult(interp, statePtr->resultList);
+ statePtr->resultList = NULL; /* Don't clean it up */
done:
ForeachCleanup(interp, statePtr);
return result;
@@ -2840,16 +2807,13 @@ finish:
static inline int
ForeachAssignments(
Tcl_Interp *interp,
- struct ForeachState *statePtr,
- int collect) /* Select collecting or accumulating mode (TCL_EACH_*) */
+ struct ForeachState *statePtr)
{
int i, v, k;
Tcl_Obj *valuePtr, *varValuePtr;
for (i=0 ; i<statePtr->numLists ; i++) {
- /* Don't modify the accumulator except on the first iteration */
- v = ((i == 0) && (collect == TCL_EACH_ACCUM) && (statePtr->index[i] > 0));
- for (; v<statePtr->varcList[i] ; v++) {
+ for (v=0 ; v<statePtr->varcList[i] ; v++) {
k = statePtr->index[i]++;
if (k < statePtr->argcList[i]) {