diff options
author | dkf <dkf@noemail.net> | 2005-06-03 10:02:19 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2005-06-03 10:02:19 (GMT) |
commit | 150b5fae315c8aa7642d1e81ca61e0b68d2f4f7a (patch) | |
tree | 09403f42f5cb2b0d85eb12ecc1bd6311da4f818c | |
parent | c30e17d81d8a971c53ac0636481347e2fd62c42d (diff) | |
download | tcl-150b5fae315c8aa7642d1e81ca61e0b68d2f4f7a.zip tcl-150b5fae315c8aa7642d1e81ca61e0b68d2f4f7a.tar.gz tcl-150b5fae315c8aa7642d1e81ca61e0b68d2f4f7a.tar.bz2 |
Remove blatant inefficiency in [parray]
FossilOrigin-Name: 602628a115abd09c14990340b1b6eaecb5ec80d1
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | library/parray.tcl | 7 |
2 files changed, 9 insertions, 3 deletions
@@ -1,3 +1,8 @@ +2005-06-03 Donal K. Fellows <donal.k.fellows@man.ac.uk> + + * library/parray.tcl (parray): Only generate the sorted list of + element names once. Thanks to Andreas Leitgeb for spotting this. + 2005-06-03 Daniel Steffen <das@users.sourceforge.net> * macosx/Makefile: fixed 'embedded' target. diff --git a/library/parray.tcl b/library/parray.tcl index 92655b2..e331d4d 100644 --- a/library/parray.tcl +++ b/library/parray.tcl @@ -1,7 +1,7 @@ # parray: # Print the contents of a global array on stdout. # -# RCS: @(#) $Id: parray.tcl,v 1.3 1998/09/14 18:40:03 stanton Exp $ +# RCS: @(#) $Id: parray.tcl,v 1.4 2005/06/03 10:02:23 dkf Exp $ # # Copyright (c) 1991-1993 The Regents of the University of California. # Copyright (c) 1994 Sun Microsystems, Inc. @@ -16,13 +16,14 @@ proc parray {a {pattern *}} { error "\"$a\" isn't an array" } set maxl 0 - foreach name [lsort [array names array $pattern]] { + set names [lsort [array names array $pattern]] + foreach name $names { if {[string length $name] > $maxl} { set maxl [string length $name] } } set maxl [expr {$maxl + [string length $a] + 2}] - foreach name [lsort [array names array $pattern]] { + foreach name $names { set nameString [format %s(%s) $a $name] puts stdout [format "%-*s = %s" $maxl $nameString $array($name)] } |