From eb97dfe76d6d46cf1b3c040b8a907305e5300afe Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 10 Sep 2008 13:03:02 +0000 Subject: Fix efficiency bug detected by Kieran Elby. --- ChangeLog | 7 +++++++ generic/tclListObj.c | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e8dc18..558d591 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-09-10 Donal K. Fellows + + * generic/tclListObj.c (Tcl_ListObjGetElements): Make this list->dict + transformation - encountered when using [foreach] with dicts - not as + expensive as it was before. Spotted by Kieran Elby and reported on + tcl-core. + 2008-09-08 Donal K. Fellows * tests/append.test, appendComp.test, cmdAH.test: Use the powers of diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 7505569..aebaee8 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.52 2008/08/23 10:54:24 dkf Exp $ + * RCS: @(#) $Id: tclListObj.c,v 1.53 2008/09/10 13:03:33 dkf Exp $ */ #include "tclInt.h" @@ -428,7 +428,16 @@ Tcl_ListObjGetElements( if (listPtr->typePtr != &tclListType) { int result, length; - (void) TclGetStringFromObj(listPtr, &length); + /* + * Don't get the string version of a dictionary; that transformation + * is not lossy, but is expensive. + */ + + if (listPtr->typePtr == &tclDictType) { + (void) Tcl_DictObjSize(NULL, listPtr, &length); + } else { + (void) TclGetStringFromObj(listPtr, &length); + } if (!length) { *objcPtr = 0; *objvPtr = NULL; -- cgit v0.12