<pre style='margin:0'>
Rainer Müller (raimue) pushed a commit to branch release-2.4
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/26fd9b60bd0e742eef37ed87ae3f23a260a71ae0">https://github.com/macports/macports-base/commit/26fd9b60bd0e742eef37ed87ae3f23a260a71ae0</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 26fd9b60bd0e742eef37ed87ae3f23a260a71ae0
</span>Author: Rainer Müller <raimue@macports.org>
AuthorDate: Sun Apr 1 13:25:41 2018 +0200
<span style='display:block; white-space:pre;color:#404040;'> macports_util: Optimize lshift and lunshift
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Before:
</span><span style='display:block; white-space:pre;color:#404040;'> % set x 0; set lst {}
</span><span style='display:block; white-space:pre;color:#404040;'> % time { lunshift lst [incr x] } 100000
</span><span style='display:block; white-space:pre;color:#404040;'> 1052.31448266 microseconds per iteration
</span><span style='display:block; white-space:pre;color:#404040;'> % time { lshift lst } 100000
</span><span style='display:block; white-space:pre;color:#404040;'> 385.37422747 microseconds per iteration
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> After:
</span><span style='display:block; white-space:pre;color:#404040;'> % set x 0; set lst {}
</span><span style='display:block; white-space:pre;color:#404040;'> % time { lunshift lst [incr x] } 100000
</span><span style='display:block; white-space:pre;color:#404040;'> 21.04909169 microseconds per iteration
</span><span style='display:block; white-space:pre;color:#404040;'> % time { lshift lst } 100000
</span><span style='display:block; white-space:pre;color:#404040;'> 45.06936868 microseconds per iteration
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> (cherry picked from commit cf998981c078c9804f1f8e0ce245796278876474)
</span>---
src/macports1.0/macports_util.tcl | 6 ++++--
1 file changed, 4 insertions(+), 2 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 441e505..e570f07 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;'>@@ -168,7 +168,8 @@ proc lpush {varName args} {
</span> proc lshift {varName} {
upvar 1 $varName var
set element [lindex $var 0]
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set var [lrange $var 1 end]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # the [set] in the index argument ensures the list is not shared
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set var [lreplace $var [set var 0] 0]
</span> return $element
}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -180,7 +181,8 @@ proc lunshift {varName args} {
</span> if {![info exists var]} {
set var {}
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set var [list {*}$args {*}$var]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # the [set] in the index argument ensures the list is not shared
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set var [lreplace $var [set var -1] -1 {*}$args]
</span> }
</pre><pre style='margin:0'>
</pre>