summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2019-05-17 10:40:17 (GMT)
committersebres <sebres@users.sourceforge.net>2019-05-17 10:40:17 (GMT)
commita68f7032b3a1880b9edd85bcf98d5a38e7705067 (patch)
treea4fd5ea3747f4eed60de918c1b4f02bc13242db3
parent503da2614f2490195b2bd436c44cc52f3678becd (diff)
parent1f5c7c693b88225d758e750677764203458dd26a (diff)
downloadtcl-a68f7032b3a1880b9edd85bcf98d5a38e7705067.zip
tcl-a68f7032b3a1880b9edd85bcf98d5a38e7705067.tar.gz
tcl-a68f7032b3a1880b9edd85bcf98d5a38e7705067.tar.bz2
merge 8.6
-rw-r--r--generic/tclCmdMZ.c47
-rw-r--r--tests/cmdMZ.test14
2 files changed, 46 insertions, 15 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index 6792378..7b83370 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -4188,6 +4188,7 @@ Tcl_TimeRateObjCmd(
};
NRE_callback *rootPtr;
ByteCode *codePtr = NULL;
+ int codeOptimized = 0;
for (i = 1; i < objc - 1; i++) {
int index;
@@ -4372,6 +4373,15 @@ Tcl_TimeRateObjCmd(
}
codePtr = TclCompileObj(interp, objPtr, NULL, 0);
TclPreserveByteCode(codePtr);
+ /*
+ * Replace last compiled done instruction with continue: it's a part of
+ * iteration, this way evaluation will be more similar to a cycle (also
+ * avoids extra overhead to set result to interp, etc.)
+ */
+ if (codePtr->codeStart[codePtr->numCodeBytes-1] == INST_DONE) {
+ codePtr->codeStart[codePtr->numCodeBytes-1] = INST_CONTINUE;
+ codeOptimized = 1;
+ }
}
/*
@@ -4418,23 +4428,25 @@ Tcl_TimeRateObjCmd(
} else { /* eval */
result = TclEvalObjEx(interp, objPtr, 0, NULL, 0);
}
- if (result != TCL_OK) {
- /*
- * Allow break from measurement cycle (used for conditional
- * stop).
- */
+ /*
+ * Allow break and continue from measurement cycle (used for
+ * conditional stop and flow control of iterations).
+ */
- if (result != TCL_BREAK) {
+ switch (result) {
+ case TCL_OK:
+ break;
+ case TCL_BREAK:
+ /*
+ * Force stop immediately.
+ */
+ threshold = 1;
+ maxcnt = 0;
+ case TCL_CONTINUE:
+ result = TCL_OK;
+ break;
+ default:
goto done;
- }
-
- /*
- * Force stop immediately.
- */
-
- threshold = 1;
- maxcnt = 0;
- result = TCL_OK;
}
/*
@@ -4660,6 +4672,11 @@ Tcl_TimeRateObjCmd(
done:
if (codePtr != NULL) {
+ if ( codeOptimized
+ && codePtr->codeStart[codePtr->numCodeBytes-1] == INST_CONTINUE
+ ) {
+ codePtr->codeStart[codePtr->numCodeBytes-1] = INST_DONE;
+ }
TclReleaseByteCode(codePtr);
}
return result;
diff --git a/tests/cmdMZ.test b/tests/cmdMZ.test
index 2c2d51c..60cc621 100644
--- a/tests/cmdMZ.test
+++ b/tests/cmdMZ.test
@@ -403,6 +403,14 @@ test cmdMZ-6.8 {Tcl_TimeRateObjCmd: allow (conditional) break from timerate} {
[expr {[lindex $m1 4] > 1000}] \
[expr {[lindex $m1 6] < 10}]
} {1 1 1 1}
+test cmdMZ-6.8.1 {Tcl_TimeRateObjCmd: allow (conditional) continue in timerate} {
+ set m1 [timerate {continue; return -code error "unexpected"} 1000 10]
+ list \
+ [expr {[lindex $m1 0] < 1000}] \
+ [expr {[lindex $m1 2] == 10}] \
+ [expr {[lindex $m1 4] > 1000}] \
+ [expr {[lindex $m1 6] < 100}]
+} {1 1 1 1}
test cmdMZ-6.9 {Tcl_TimeRateObjCmd: max count of iterations} {
set m1 [timerate {} 1000 5]; # max-count wins
set m2 [timerate {_nrt_sleep 20} 1 5]; # max-time wins
@@ -416,6 +424,12 @@ test cmdMZ-6.10 {Tcl_TimeRateObjCmd: huge overhead cause 0us result} {
[expr {[lindex $m1 4] == 1000000}] \
[expr {[lindex $m1 6] <= 0.001}]
} {1 1 1 1}
+test cmdMZ-6.11 {Tcl_TimeRateObjCmd: done/continue optimization rollback} {
+ set m1 {set m2 ok}
+ if 1 $m1
+ timerate $m1 1000 10
+ if 1 $m1; # if rollback is missing throws an error: invoked "continue" outside of a loop
+} ok
test cmdMZ-try-1.0 {