Artifacts Associated With Ticket 217802ffffffffff
Ticket change [4ad7a26af4] (rid 126597) by nobody on 2000-10-26 00:43:55:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
OriginalBugID: 1007 RFE Version: 8.1b2 SubmitDate: '1998-12-22' LastModified: '1998-12-22' Severity: LOW Status: Closed Submitter: welch ChangedBy: rjohnson RelatedBugIDs: 726 OS: Windows NT OSVersion: 4.0 Machine: X86 FixedDate: '1998-12-22' ClosedDate: '2000-10-25' Name: Syd Polk CVS: tclCmdIL.c 1998/11/11 04:08:15 1.1.2.4 DesiredBehavior: I am submitting a patch to change lsort -command to use a Tcl_Obj-based command instead of a string based command. This is substantially faster. Patch: Index: tclCmdIL.c =================================================================== RCS file: /cvsroot/tcl/generic/tclCmdIL.c,v retrieving revision 1.1.2.4 diff -c -r1.1.2.4 tclCmdIL.c *** tclCmdIL.c1998/11/11 04:08:151.1.2.4 --- tclCmdIL.c1998/12/18 19:41:47 *************** *** 46,52 **** int isIncreasing;/* Nonzero means sort in increasing order. */ int sortMode;/* The sort mode. One of SORTMODE_* * values defined below */ ! Tcl_DString compareCmd;/* The Tcl comparison command when sortMode * is SORTMODE_COMMAND. Pre-initialized to * hold base of command.*/ int index;/* If the -index option was specified, this --- 46,52 ---- int isIncreasing;/* Nonzero means sort in increasing order. */ int sortMode;/* The sort mode. One of SORTMODE_* * values defined below */ ! Tcl_Obj *compareCmdPtr; /* The Tcl comparison command when sortMode * is SORTMODE_COMMAND. Pre-initialized to * hold base of command.*/ int index;/* If the -index option was specified, this *************** *** 2514,2521 **** } } if (sortInfo.sortMode == SORTMODE_COMMAND) { ! Tcl_DStringInit(&sortInfo.compareCmd); ! Tcl_DStringAppend(&sortInfo.compareCmd, Tcl_GetString(cmdPtr), -1); } sortInfo.resultCode = Tcl_ListObjGetElements(interp, objv[objc-1], --- 2514,2535 ---- } } if (sortInfo.sortMode == SORTMODE_COMMAND) { ! ! /* ! * The existing command is a list. We want to flatten it, append ! * two dummy arguments on the end, and replace these arguments ! * later. ! */ ! ! Tcl_Obj *newCommandPtr = Tcl_DuplicateObj(cmdPtr); ! ! if (Tcl_ListObjAppendElement(interp, newCommandPtr, Tcl_NewObj()) ! != TCL_OK) { ! return TCL_ERROR; ! } ! Tcl_ListObjAppendElement(interp, newCommandPtr, Tcl_NewObj()); ! sortInfo.compareCmdPtr = newCommandPtr; ! Tcl_IncrRefCount(newCommandPtr); } sortInfo.resultCode = Tcl_ListObjGetElements(interp, objv[objc-1], *************** *** 2549,2555 **** done: if (sortInfo.sortMode == SORTMODE_COMMAND) { ! Tcl_DStringFree(&sortInfo.compareCmd); } return sortInfo.resultCode; } --- 2563,2570 ---- done: if (sortInfo.sortMode == SORTMODE_COMMAND) { ! Tcl_DecrRefCount(sortInfo.compareCmdPtr); ! sortInfo.compareCmdPtr = NULL; } return sortInfo.resultCode; } *************** *** 2805,2826 **** order = -1; } } else { ! int oldLength; ! /* ! * Generate and evaluate a command to determine which string comes ! * first. */ - oldLength = Tcl_DStringLength(&infoPtr->compareCmd); - Tcl_DStringAppendElement(&infoPtr->compareCmd, - Tcl_GetString(objPtr1)); - Tcl_DStringAppendElement(&infoPtr->compareCmd, - Tcl_GetString(objPtr2)); - infoPtr->resultCode = Tcl_Eval(infoPtr->interp, - Tcl_DStringValue(&infoPtr->compareCmd)); - Tcl_DStringTrunc(&infoPtr->compareCmd, oldLength); if (infoPtr->resultCode != TCL_OK) { Tcl_AddErrorInfo(infoPtr->interp, "\n (-compare command)"); return order; --- 2820,2845 ---- order = -1; } } else { ! Tcl_Obj **objv, *paramObjv[2] = {objPtr1, objPtr2}; ! int objc; ! /* ! * We made space for the two things to compare. Replace them ! * and evaluate the result. */ + + Tcl_ListObjLength(infoPtr->interp, infoPtr->compareCmdPtr, &objc); + Tcl_ListObjReplace(infoPtr->interp, infoPtr->compareCmdPtr, objc - 2, + 2, 2, paramObjv); + Tcl_ListObjGetElements(infoPtr->interp, infoPtr->compareCmdPtr, + &objc, &objv); + + infoPtr->resultCode = Tcl_EvalObjv(infoPtr->interp, objc, objv, 0); if (infoPtr->resultCode != TCL_OK) { + Tcl_Obj *errorPtr = Tcl_NewListObj(3, objv); + int length; + char *compareCmd = Tcl_GetStringFromObj(errorPtr, &length); Tcl_AddErrorInfo(infoPtr->interp, "\n (-compare command)"); return order; PatchFiles: generic/tclCmdIL.c This slightly changes the semantics of lsort -command. If you have a command in the form: lsort $list -command [generate random command] this patch will break it. It will work in the normal cases, like lsort $list -command mysort lsort $list -command sorter up lsort $list -command sorter down and it passes the test suite. I applied the patch and can not confirm the problem listed above. It appeared to work fine. (A script that would break would have been useful!) Also, the patch certainly improves the performace - it makes sorting with the -command option about 5 times faster. 12/22/1998 18:47 - rjohnson - - foundin initialized to: "obsolete: 8.1b2"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "69. Other"
- title initialized to: "lsort -command is too slow"
- type initialized to: "Bug"
Ticket change [c1a82c5405] (rid 111357) by welch on 2000-10-26 07:49:18:
- priority changed to: "1 Zero"
- status changed to: "Closed"
Ticket change [60f8d81953] (rid 92160) by welch on 2000-10-26 07:49:19:
- closedate changed to: "2000-10-26T00:49:19"
- closer changed to: "welch"
- resolution changed to: "Duplicate"
Ticket change [8f1675945f] (rid 120222) by dgp on 2001-04-13 23:04:16:
- closedate changed to: "2001-04-13T16:04:16"
- closer changed to: "dgp"
- subsystem changed to: "17. Commands I-L"