<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch master
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/24352161829f18c561d8538d8200a5eed2d0b779">https://github.com/macports/macports-base/commit/24352161829f18c561d8538d8200a5eed2d0b779</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 24352161829f18c561d8538d8200a5eed2d0b779
</span>Author: Joshua Root <jmr@macports.org>
AuthorDate: Fri Dec 2 15:54:54 2016 +1100
<span style='display:block; white-space:pre;color:#404040;'> Use upvar in list management procs
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This replaces some unnecessarily complicated use of uplevel.
</span>---
src/macports1.0/macports_util.tcl | 47 +++++++++++++++++++--------------------
1 file changed, 23 insertions(+), 24 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/macports1.0/macports_util.tcl b/src/macports1.0/macports_util.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index bdfb145..4cb9e16 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/macports1.0/macports_util.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/macports1.0/macports_util.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -136,10 +136,10 @@ namespace eval macports_util {
</span> # If no indexes are provided, deletes the entire list and returns it
# If varName does not exists an exception is raised
proc ldindex {varName args} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set varName [list $varName]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upvar 1 $varName var
</span> if {[llength $args] > 0} {
set idx [lindex $args 0]
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set size [uplevel 1 [subst -nocommands {llength [set $varName]}]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set size [llength $var]
</span> set badrange? 0
if {[string is integer -strict $idx]} {
if {$idx < 0 || $idx >= $size} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -162,16 +162,16 @@ proc ldindex {varName args} {
</span> }
if {[llength $args] > 1} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set list [uplevel 1 [subst -nocommands {lindex [set $varName] $idx}]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set list [lindex $var $idx]
</span> set item [ldindex list {*}[lrange $args 1 end]]
<span style='display:block; white-space:pre;background:#ffe0e0;'>- uplevel 1 [subst {lset $varName $idx [list $list]}]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ lset var $idx $list
</span> } else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set item [uplevel 1 [subst -nocommands {lindex [set $varName] $idx}]]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- uplevel 1 [subst -nocommands {set $varName [lreplace [set $varName] $idx $idx]}]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set item [lindex $var $idx]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set var [lreplace $var $idx $idx]
</span> }
} else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set item [uplevel 1 [subst {set $varName}]]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- uplevel 1 [subst {set $varName {}}]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set item $var
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set var {}
</span> }
return $item
}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -181,11 +181,12 @@ macports_util::method_wrap ldindex
</span> # Removes the last list element from a variable
# If varName is an empty list an empty string is returned
proc lpop {varName} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set varName [list $varName]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set size [uplevel 1 [subst -nocommands {llength [set $varName]}]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upvar 1 $varName var
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set size [llength $var]
</span> if {$size != 0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- uplevel 1 [subst -nocommands {ldindex $varName end}]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return [ldindex var end]
</span> }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ return {}
</span> }
macports_util::method_wrap lpop
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -194,8 +195,8 @@ macports_util::method_wrap lpop
</span> # If varName does not exist then it is created
# really just an alias for lappend
proc lpush {varName args} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set varName [list $varName]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- uplevel 1 [subst -nocommands {lappend $varName $args}]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upvar 1 $varName var
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ lappend var {*}$args
</span> }
macports_util::method_wrap lpush
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -203,11 +204,12 @@ macports_util::method_wrap lpush
</span> # Removes the first list element from a variable
# If varName is an empty list an empty string is returned
proc lshift {varName} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set varName [list $varName]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set size [uplevel 1 [subst -nocommands {llength [set $varName]}]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upvar 1 $varName var
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set size [llength $var]
</span> if {$size != 0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- uplevel 1 [subst -nocommands {ldindex $varName 0}]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return [ldindex var 0]
</span> }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ return {}
</span> }
macports_util::method_wrap lshift
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -215,14 +217,11 @@ macports_util::method_wrap lshift
</span> # Prepends list elements onto a variable
# If varName does not exist then it is created
proc lunshift {varName args} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set varName [list $varName]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- uplevel 1 [subst -nocommands {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists $varName]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set $varName {}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set value [concat $args [uplevel 1 set $varName]]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- uplevel 1 set $varName [list $value]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upvar 1 $varName var
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {![info exists var]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set var {}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set var [list {*}$args {*}$var]
</span> }
macports_util::method_wrap lunshift
</pre><pre style='margin:0'>
</pre>