From 96d1d0f2dd821c789b8178f9e23d7afef194aa35 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 1 Mar 2007 22:14:18 +0000 Subject: * generic/tclCmdIL.c (Tcl_LreplaceObjCmd): Code simplifications and optimizations. --- ChangeLog | 3 +++ generic/tclCmdIL.c | 24 +++++------------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c9e185..07e8268 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-03-01 Don Porter + * generic/tclCmdIL.c (Tcl_LreplaceObjCmd): Code simplifications + and optimizations. + * generic/tclCmdIL.c (Tcl_LrangeObjCmd): Rewrite in the same spirit; avoid shimmer effects rather than react to them. diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 56e4a9e..770d990 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.100 2007/03/01 21:03:20 dgp Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.101 2007/03/01 22:14:19 dgp Exp $ */ #include "tclInt.h" @@ -3272,7 +3272,7 @@ Tcl_LreplaceObjCmd( Tcl_Obj *CONST objv[]) /* Argument objects. */ { register Tcl_Obj *listPtr; - int isDuplicate, first, last, listLen, numToDelete, result; + int first, last, listLen, numToDelete, result; if (objc < 4) { Tcl_WrongNumArgs(interp, 1, objv, @@ -3307,7 +3307,7 @@ Tcl_LreplaceObjCmd( /* * Complain if the user asked for a start element that is greater than the - * list length. This won't ever trigger for the "end*" case as that will + * list length. This won't ever trigger for the "end-*" case as that will * be properly constrained by TclGetIntForIndex because we use listLen-1 * (to allow for replacing the last elem). */ @@ -3332,24 +3332,10 @@ Tcl_LreplaceObjCmd( */ listPtr = objv[1]; - isDuplicate = 0; if (Tcl_IsShared(listPtr)) { - listPtr = Tcl_DuplicateObj(listPtr); - isDuplicate = 1; - } - if (objc > 4) { - result = Tcl_ListObjReplace(interp, listPtr, first, numToDelete, - (objc-4), &(objv[4])); - } else { - result = Tcl_ListObjReplace(interp, listPtr, first, numToDelete, - 0, NULL); - } - if (result != TCL_OK) { - if (isDuplicate) { - Tcl_DecrRefCount(listPtr); /* free unneeded obj */ - } - return result; + listPtr = TclListObjCopy(NULL, listPtr); } + Tcl_ListObjReplace(NULL, listPtr, first, numToDelete, objc-4, &(objv[4])); /* * Set the interpreter's object result. -- cgit v0.12