From 986970a95155cda5c067008629993af20bd86e52 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 2 Mar 2007 16:06:32 +0000 Subject: Added comments warning against certain optimizations --- generic/tclCmdIL.c | 11 ++++++++++- generic/tclListObj.c | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 734c1dd..05aa154 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -16,7 +16,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdIL.c,v 1.104 2007/03/02 15:11:20 dgp Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.105 2007/03/02 16:06:32 dgp Exp $ */ #include "tclInt.h" @@ -3309,6 +3309,15 @@ Tcl_LreplaceObjCmd( if (Tcl_IsShared(listPtr)) { listPtr = TclListObjCopy(NULL, listPtr); } + + /* + * Note that we call Tcl_ListObjReplace even when numToDelete == 0 + * and objc == 4. In this case, the list value of listPtr is not + * changed (no elements are removed or added), but by making the + * call we are assured we end up with a list in canonical form. + * Resist any temptation to optimize this case away. + */ + Tcl_ListObjReplace(NULL, listPtr, first, numToDelete, objc-4, &(objv[4])); /* diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 35db836..6887207 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclListObj.c,v 1.35 2007/02/24 18:55:43 dgp Exp $ + * RCS: @(#) $Id: tclListObj.c,v 1.36 2007/03/02 16:06:33 dgp Exp $ */ #include "tclInt.h" @@ -804,6 +804,14 @@ Tcl_ListObjReplace( } } + /* + * Note that when count == 0 and objc == 0, this routine is logically + * a no-op, removing and adding no elements to the list. However, by + * flowing through this routine anyway, we get the important side effect + * that the resulting listPtr is a list in canoncial form. This is + * important. Resist any temptation to optimize this case. + */ + listRepPtr = (List *) listPtr->internalRep.twoPtrValue.ptr1; elemPtrs = &listRepPtr->elements; numElems = listRepPtr->elemCount; -- cgit v0.12