summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdIL.c
diff options
context:
space:
mode:
authorMiguel Sofer <miguel.sofer@gmail.com>2007-12-22 01:59:10 (GMT)
committerMiguel Sofer <miguel.sofer@gmail.com>2007-12-22 01:59:10 (GMT)
commit2ca3e4c31fb0c6eb8106bc1345e80ec93056562d (patch)
tree846defe00369a08e9469c8ad116ef19f4c70e885 /generic/tclCmdIL.c
parentbe3803aca6bc4d8286f24850bffc9937cfd520bb (diff)
downloadtcl-2ca3e4c31fb0c6eb8106bc1345e80ec93056562d.zip
tcl-2ca3e4c31fb0c6eb8106bc1345e80ec93056562d.tar.gz
tcl-2ca3e4c31fb0c6eb8106bc1345e80ec93056562d.tar.bz2
* generic/tclCmdIL.c (Tcl_LsortObjCmd): preallocate a listObj of
sufficient length for the sorted list instead of growing it. Second commit replaces calls to Tcl_ListObjAppenElement with direct access to the internal rep.
Diffstat (limited to 'generic/tclCmdIL.c')
-rw-r--r--generic/tclCmdIL.c36
1 files changed, 24 insertions, 12 deletions
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);