Artifacts Associated With Ticket 219110
Ticket change [51b8e3bed1] (rid 126180) by nobody on 2000-10-26 01:10:57:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
OriginalBugID: 6019 RFE Version: 8.2 SubmitDate: '2000-07-18' LastModified: '2000-07-18' Severity: MED Status: Released Submitter: techsupp ChangedBy: ericm OS: All FixedDate: '2000-07-18' FixedInVersion: 8.4a2 ClosedDate: '2000-10-25' Name: Chris Nelson CVS: 1.2 DesiredBehavior: optproc makes extensive use of Lfirst and Lrest which do nothing but obfuscate lindex and lrange and add procedure call overhead. This fix replaces those calls with direct use of lindex and lrange resulting in a significant speedup. Patch: Index: optparse.tcl =================================================================== RCS file: /cvsroot/tcl/library/opt0.4/optparse.tcl,v retrieving revision 1.2 diff -c -r1.2 optparse.tcl *** optparse.tcl 1999/04/16 00:47:18 1.2 --- optparse.tcl 2000/07/18 12:40:37 *************** *** 18,24 **** namespace export OptKeyRegister OptKeyDelete OptKeyError OptKeyParse \ OptProc OptProcArgGiven OptParse \ Lempty Lget \ ! Lassign Lvarpop Lvarpop1 Lvarset Lvarincr Lfirst Lrest \ SetMax SetMin --- 18,24 ---- namespace export OptKeyRegister OptKeyDelete OptKeyError OptKeyParse \ OptProc OptProcArgGiven OptParse \ Lempty Lget \ ! Lassign Lvarpop Lvarpop1 Lvarset Lvarincr \ SetMax SetMin *************** *** 174,180 **** return -code error "'args' special argument must be the last one"; } set res [OptNormalizeOne $item]; ! set state [Lfirst $res]; if {$inflags} { if {$state == "flags"} { # add to 'subprogram' --- 174,180 ---- return -code error "'args' special argument must be the last one"; } set res [OptNormalizeOne $item]; ! set state [lindex $res 0] if {$inflags} { if {$state == "flags"} { # add to 'subprogram' *************** *** 277,283 **** # Return the instruction word/list of a given step/(sub)program proc OptInstr {lst} { ! Lfirst $lst; } # Is a (sub) program or a plain instruction ? proc OptIsPrg {lst} { --- 277,283 ---- # Return the instruction word/list of a given step/(sub)program proc OptInstr {lst} { ! lindex $lst 0 } # Is a (sub) program or a plain instruction ? proc OptIsPrg {lst} { *************** *** 285,291 **** } # Is this instruction a program counter or a real instr proc OptIsCounter {item} { ! expr {[Lfirst $item]=="P"} } # Current program counter (2nd word of first word) proc OptGetPrgCounter {lst} { --- 285,291 ---- } # Is this instruction a program counter or a real instr proc OptIsCounter {item} { ! expr {[lindex $item 0]=="P"} } # Current program counter (2nd word of first word) proc OptGetPrgCounter {lst} { *************** *** 299,305 **** # returns a list of currently selected items. proc OptSelection {lst} { set res {}; ! foreach idx [lrange [Lfirst $lst] 1 end] { lappend res [Lget $lst $idx]; } return $res; --- 299,305 ---- # returns a list of currently selected items. proc OptSelection {lst} { set res {}; ! foreach idx [lrange [lindex $lst 0] 1 end] { lappend res [Lget $lst $idx]; } return $res; *************** *** 348,354 **** # empty state means done/paste the end of the program proc OptState {item} { ! Lfirst $item } # current state --- 348,354 ---- # empty state means done/paste the end of the program proc OptState {item} { ! lindex $item 0 } # current state *************** *** 361,367 **** # Returns the argument that has to be processed now proc OptCurrentArg {lst} { ! Lfirst $lst; } # Advance to next argument proc OptNextArg {argsName} { --- 361,367 ---- # Returns the argument that has to be processed now proc OptCurrentArg {lst} { ! lindex $lst 0 } # Advance to next argument proc OptNextArg {argsName} { *************** *** 962,968 **** if {[llength $indexLst] <= 1} { return [lindex $list $indexLst]; } ! Lget [lindex $list [Lfirst $indexLst]] [Lrest $indexLst]; } # Sets the value of one leaf of a lists tree # (we use the version that does not create the elements because --- 962,968 ---- if {[llength $indexLst] <= 1} { return [lindex $list $indexLst]; } ! Lget [lindex $list [lindex $indexLst 0]] [lrange $indexLst 1 end]; } # Sets the value of one leaf of a lists tree # (we use the version that does not create the elements because *************** *** 977,989 **** if {[llength $indexLst] <= 1} { Lvarset1nc list $indexLst $newValue; } else { ! set idx [Lfirst $indexLst]; set targetList [lindex $list $idx]; # reduce refcount on targetList (not really usefull now, # could be with optimizing compiler) # Lvarset1 list $idx {}; # recursively replace in targetList ! Lvarset targetList [Lrest $indexLst] $newValue; # put updated sub list back in the tree Lvarset1nc list $idx $targetList; } --- 977,989 ---- if {[llength $indexLst] <= 1} { Lvarset1nc list $indexLst $newValue; } else { ! set idx [lindex $indexLst 0] set targetList [lindex $list $idx]; # reduce refcount on targetList (not really usefull now, # could be with optimizing compiler) # Lvarset1 list $idx {}; # recursively replace in targetList ! Lvarset targetList [lrange $indexLst 1 end] $newValue; # put updated sub list back in the tree Lvarset1nc list $idx $targetList; } *************** *** 1017,1028 **** if {[llength $indexLst] <= 1} { Lvarincr1 list $indexLst $howMuch; } else { ! set idx [Lfirst $indexLst]; set targetList [lindex $list $idx]; # reduce refcount on targetList Lvarset1nc list $idx {}; # recursively replace in targetList ! Lvarincr targetList [Lrest $indexLst] $howMuch; # put updated sub list back in the tree Lvarset1nc list $idx $targetList; } --- 1017,1028 ---- if {[llength $indexLst] <= 1} { Lvarincr1 list $indexLst $howMuch; } else { ! set idx [lindex $indexLst 0] set targetList [lindex $list $idx]; # reduce refcount on targetList Lvarset1nc list $idx {}; # recursively replace in targetList ! Lvarincr targetList [lrange $indexLst 1 end] $howMuch; # put updated sub list back in the tree Lvarset1nc list $idx $targetList; } *************** *** 1034,1047 **** set list [lreplace $list $index $index $newValue]; return $newValue; } - # Returns the first element of a list - proc ::tcl::Lfirst {list} { - lindex $list 0 - } - # Returns the rest of the list minus first element - proc ::tcl::Lrest {list} { - lrange $list 1 end - } # Removes the first element of a list # and returns the new list value proc ::tcl::Lvarpop1 {listName} { --- 1034,1039 ---- *************** *** 1052,1058 **** # (Like the tclX version) proc ::tcl::Lvarpop {listName} { upvar $listName list; ! set el [Lfirst $list]; set list [lrange $list 1 end]; return $el; } --- 1044,1050 ---- # (Like the tclX version) proc ::tcl::Lvarpop {listName} { upvar $listName list; ! set el [lindex $list 0]; set list [lrange $list 1 end]; return $el; } PatchFiles: optparse.tcl There were some problems with the diff you sent; several of the hunks failed to patch against the source I had, although I don't know why. But I merged the patch by hand, and updated the test suite as well, to accomodate for the lack of the Lfirst and Lrest functions. This work will be in Tcl 8.4a2. You should consider using the cmdline library in tcllib for future work, as opt is deprecated, less functional, and will only have minimal maintainence work done on it in the future. There should be a "sumo-distribution" of Tcl 8.4.0 that includes tcllib. Thanks for the patch! Eric Melski The Other Tcl Guy ericm at ajubasolutions.com Ajuba Solutions -- 07/18/2000 ericm - foundin initialized to: "obsolete: 8.2"
- 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: "optproc efficientcy"
- type initialized to: "RFE"
Ticket change [b222997556] (rid 98282) by welch on 2000-10-26 08:34:57:
- closedate changed to: "2000-10-26T01:34:57"
- closer changed to: "welch"
- priority changed to: "2"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [37951206d3] (rid 107308) by dgp on 2001-04-19 03:40:29:
- foundin changed to: "None"
- status changed to: "Open"
- subsystem changed to: "None"
Ticket change [4f0f6e6a92] (rid 125758) by dgp on 2001-04-19 03:41:24:
- closedate changed to: "2001-04-18T20:41:24"
- closer changed to: "dgp"
- status changed to: "Closed"
- subsystem changed to: "31. opt Package"