diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | generic/tclCmdIL.c | 36 |
2 files changed, 27 insertions, 13 deletions
@@ -1,7 +1,9 @@ 2007-12-21 Miguel Sofer <msofer@users.sf.net> * generic/tclCmdIL.c (Tcl_LsortObjCmd): preallocate a listObj of - sufficient length for the sorted list instead of growing it. + sufficient length for the sorted list instead of growing + it. Second commit replaces calls to Tcl_ListObjAppenElement with + direct access to the internal rep. 2007-12-19 Don Porter <dgp@users.sourceforge.net> diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index cd89ec3..a41b611b 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.130 2007/12/22 00:58:21 msofer Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.131 2007/12/22 01:59:10 msofer Exp $ */ #include "tclInt.h" @@ -3605,33 +3605,45 @@ Tcl_LsortObjCmd( elementArray[length-1].nextPtr = NULL; elementPtr = MergeSort(elementArray, &sortInfo); if (sortInfo.resultCode == TCL_OK) { + List *listRepPtr; + Tcl_Obj **newArray, *objPtr; + int i; + resultPtr = Tcl_NewListObj(length, NULL); + listRepPtr = (List *) resultPtr->internalRep.twoPtrValue.ptr1; + newArray = &listRepPtr->elements; if (unique) { if (indices) { - for (; elementPtr != NULL ; elementPtr = elementPtr->nextPtr){ + for (i = 0; elementPtr != NULL ; elementPtr = elementPtr->nextPtr){ if (elementPtr->count == 0) { - Tcl_ListObjAppendElement(NULL, resultPtr, - Tcl_NewIntObj(elementPtr - &elementArray[0])); + objPtr = Tcl_NewIntObj(elementPtr - &elementArray[0]); + newArray[i++] = objPtr; + Tcl_IncrRefCount(objPtr); } } } else { - for (; elementPtr != NULL; elementPtr = elementPtr->nextPtr) { + for (i = 0; elementPtr != NULL ; elementPtr = elementPtr->nextPtr){ if (elementPtr->count == 0) { - Tcl_ListObjAppendElement(NULL, resultPtr, - elementPtr->objPtr); + objPtr = elementPtr->objPtr; + newArray[i++] = objPtr; + Tcl_IncrRefCount(objPtr); } } } } else if (indices) { - for (; elementPtr != NULL ; elementPtr = elementPtr->nextPtr) { - Tcl_ListObjAppendElement(NULL, resultPtr, - Tcl_NewIntObj(elementPtr - &elementArray[0])); + for (i = 0; elementPtr != NULL ; elementPtr = elementPtr->nextPtr){ + objPtr = Tcl_NewIntObj(elementPtr - &elementArray[0]); + newArray[i++] = objPtr; + Tcl_IncrRefCount(objPtr); } } else { - for (; elementPtr != NULL; elementPtr = elementPtr->nextPtr) { - Tcl_ListObjAppendElement(NULL, resultPtr, elementPtr->objPtr); + for (i = 0; elementPtr != NULL ; elementPtr = elementPtr->nextPtr){ + objPtr = elementPtr->objPtr; + newArray[i++] = objPtr; + Tcl_IncrRefCount(objPtr); } } + listRepPtr->elemCount = i; Tcl_SetObjResult(interp, resultPtr); } TclStackFree(interp, elementArray); |