Patchwork [3,of,3] hgk: use switch instead of a less efficient if/elseif/if

login
register
mail settings
Submitter Andrew Shadura
Date March 29, 2015, 5:18 p.m.
Message ID <dda00b516e548b41b12b.1427649480@localhost.localdomain>
Download mbox | patch
Permalink /patch/8351/
State Accepted
Headers show

Comments

Andrew Shadura - March 29, 2015, 5:18 p.m.
# HG changeset patch
# User Andrew Shadura <andrew@shadura.me>
# Date 1427649304 -7200
#      Sun Mar 29 19:15:04 2015 +0200
# Node ID dda00b516e548b41b12b7e591a1595ee230b2862
# Parent  277dbd26cb26103d856bc76ebe5a33029edca4dc
hgk: use switch instead of a less efficient if/elseif/if
Matt Mackall - March 31, 2015, 11:54 a.m.
On Sun, 2015-03-29 at 19:18 +0200, Andrew Shadura wrote:
> # HG changeset patch
> # User Andrew Shadura <andrew@shadura.me>
> # Date 1427649304 -7200
> #      Sun Mar 29 19:15:04 2015 +0200
> # Node ID dda00b516e548b41b12b7e591a1595ee230b2862
> # Parent  277dbd26cb26103d856bc76ebe5a33029edca4dc
> hgk: use switch instead of a less efficient if/elseif/if

These are queued for default, thanks.
Pierre-Yves David - March 31, 2015, 8:21 p.m.
On 03/29/2015 10:18 AM, Andrew Shadura wrote:
> # HG changeset patch
> # User Andrew Shadura <andrew@shadura.me>
> # Date 1427649304 -7200
> #      Sun Mar 29 19:15:04 2015 +0200
> # Node ID dda00b516e548b41b12b7e591a1595ee230b2862
> # Parent  277dbd26cb26103d856bc76ebe5a33029edca4dc
> hgk: use switch instead of a less efficient if/elseif/if

I'm curious about the result of this series. Do you have picture of it 
anywhere?
Andrew Shadura - March 31, 2015, 8:50 p.m.
Hello,

On Tue, 31 Mar 2015 13:21:19 -0700
Pierre-Yves David <pierre-yves.david@ens-lyon.org> wrote:

> On 03/29/2015 10:18 AM, Andrew Shadura wrote:
> > # HG changeset patch
> > # User Andrew Shadura <andrew@shadura.me>
> > # Date 1427649304 -7200
> > #      Sun Mar 29 19:15:04 2015 +0200
> > # Node ID dda00b516e548b41b12b7e591a1595ee230b2862
> > # Parent  277dbd26cb26103d856bc76ebe5a33029edca4dc
> > hgk: use switch instead of a less efficient if/elseif/if

> I'm curious about the result of this series. Do you have picture of
> it anywhere?

Here's a screenshot:

https://dl.dropboxusercontent.com/u/41275960/hgk.png

Unfortunately, currently Tk doesn't do antialiasing for canvas, so it's
not that pretty as it could be :)

Patch

diff --git a/contrib/hgk b/contrib/hgk
--- a/contrib/hgk
+++ b/contrib/hgk
@@ -375,25 +375,25 @@  proc parsecommit {id contents listed old
 		set inhdr 0
 	    } else {
 		set tag [lindex $line 0]
-		if {$tag == "author"} {
+		switch -- $tag "author" {
 		    set x [expr {[llength $line] - 2}]
 		    set audate [lindex $line $x]
 		    set auname [join [lrange $line 1 [expr {$x - 1}]]]
-		} elseif {$tag == "committer"} {
+		} "committer" {
 		    set x [expr {[llength $line] - 2}]
 		    set comdate [lindex $line $x]
 		    set comname [join [lrange $line 1 [expr {$x - 1}]]]
-		} elseif {$tag == "revision"} {
+		} "revision" {
 		    set rev [lindex $line 1]
-        } elseif {$tag == "branch"} {
+		} "branch" {
 		    set branch [join [lrange $line 1 end]]
-        } elseif {$tag == "bookmark"} {
+		} "bookmark" {
 		    set bookmark [join [lrange $line 1 end]]
-        } elseif {$tag == "obsolete"} {
+		} "obsolete" {
 		    set obsolete($id) ""
-        } elseif {$tag == "phase"} {
+		} "phase" {
 		    set phase [lindex $line 1 end]
-        }
+		}
 	    }
 	} else {
 	    if {$comment == {}} {