summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2019-12-24 13:14:59 (GMT)
committerfvogel <fvogelnew1@free.fr>2019-12-24 13:14:59 (GMT)
commit46ffc538b8aa3e274e4c8b567de60ee2db34a16f (patch)
tree691bb6c262db9f1baeba41fa14f808ea9bb9f111
parentb701fc4005aa9bcac2fa922c63099ed6f3c36b48 (diff)
downloadtk-46ffc538b8aa3e274e4c8b567de60ee2db34a16f.zip
tk-46ffc538b8aa3e274e4c8b567de60ee2db34a16f.tar.gz
tk-46ffc538b8aa3e274e4c8b567de60ee2db34a16f.tar.bz2
A first implementation fixing [587937fff]: Don't shuffle tag list sequence upon deletion. This implementation is not efficient (it's O(n^2)) and will not be kept.
-rw-r--r--generic/tkCanvas.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c
index ce3dad1..b2007ea 100644
--- a/generic/tkCanvas.c
+++ b/generic/tkCanvas.c
@@ -1436,7 +1436,7 @@ CanvasWidgetCmd(
}
case CANV_DTAG: {
Tk_Uid tag;
- int i;
+ int i, j;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "tagOrId ?tagToDelete?");
@@ -1449,12 +1449,16 @@ CanvasWidgetCmd(
tag = Tk_GetUid(Tcl_GetString(objv[2]));
}
FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
- for (i = itemPtr->numTags-1; i >= 0; i--) {
- if (itemPtr->tagPtr[i] == tag) {
- itemPtr->tagPtr[i] = itemPtr->tagPtr[itemPtr->numTags-1];
- itemPtr->numTags--;
- }
- }
+ for (i = 0; i < itemPtr->numTags; i++) {
+ if (itemPtr->tagPtr[i] == tag) {
+ for (j = i; j < itemPtr->numTags - 1; j++) {
+ itemPtr->tagPtr[j] = itemPtr->tagPtr[j+1];
+ }
+ itemPtr->numTags--;
+ i--; /* deal with the case of successive identical tag to remove */
+ /* No break here: all tags with the same name must be deleted */
+ }
+ }
}
break;
}