On Monday, August 13, 2018 at 6:57:12 PM UTC+2, Alexandru wrote:
> set idx [lsearch $args -stride]
This creates a string representation for all elements of the searched list, if no -stride is found. You could (at least) make a shortcut to legacy lsearch, if {2 >= [llength $args]}. It might even be worth to extract [lrange $args 0 end-2] and only process these as switches ...
Use cases of lsearch will unlikely make this micro-optimization worth, but learning insights of Tcl does ;-)
#!/usr/bin/env tclsh
set longlist [lmap void [lrepeat 100000 0] {::tcl::mathfunc::rand}]
set longargs [list -index 0 -stride 2 $longlist]
set shortargs [list $longlist]
puts stderr [::tcl::unsupported::representation $longargs]
puts stderr "Early find: [time {lsearch $longargs -stride}]"
puts stderr [::tcl::unsupported::representation $shortargs]
puts stderr [::tcl::unsupported::representation [lindex $shortargs end]] ;# no string rep
puts stderr [::tcl::unsupported::representation $longlist] ;# $longlist wasn't string compared yet
puts stderr "Create string rep: [time {lsearch $shortargs -stride}]"
puts stderr [::tcl::unsupported::representation $shortargs] ;# no string rep; just for all items
puts stderr [::tcl::unsupported::representation [lindex $shortargs end]] ;# string rep created
puts stderr [::tcl::unsupported::representation $longlist] ;# note the side-effect on $longlist
puts stderr "String rep available: [time {lsearch $shortargs -stride}]"