]> Cypherpunks repositories - gostls13.git/commitdiff
go/scanner: Simplify ErrorList.Sort implementation.
authorDavid Symonds <dsymonds@golang.org>
Wed, 1 Apr 2015 21:24:35 +0000 (14:24 -0700)
committerDavid Symonds <dsymonds@golang.org>
Wed, 1 Apr 2015 21:32:47 +0000 (21:32 +0000)
It functions exactly the same, but this is the more common
style for these kinds of multi-key comparison functions,
and is more regular.

Change-Id: I46630948f893bcc96c05eb3d36eb82e1d97a6fa0
Reviewed-on: https://go-review.googlesource.com/8358
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/scanner/errors.go

index 7c9ab254eed26ea8a23341b65dd5100a3fb4e8d4..bf7bfa30e4bcc261f1985bb02cf8193a6822c6cb 100644 (file)
@@ -54,25 +54,16 @@ func (p ErrorList) Less(i, j int) bool {
        // Note that it is not sufficient to simply compare file offsets because
        // the offsets do not reflect modified line information (through //line
        // comments).
-       if e.Filename < f.Filename {
-               return true
+       if e.Filename != f.Filename {
+               return e.Filename < f.Filename
        }
-       if e.Filename == f.Filename {
-               if e.Line < f.Line {
-                       return true
-               }
-               if e.Line == f.Line {
-                       if e.Column < f.Column {
-                               return true
-                       }
-                       if e.Column == f.Column {
-                               if p[i].Msg < p[j].Msg {
-                                       return true
-                               }
-                       }
-               }
+       if e.Line != f.Line {
+               return e.Line < f.Line
+       }
+       if e.Column != f.Column {
+               return e.Column < f.Column
        }
-       return false
+       return p[i].Msg < p[j].Msg
 }
 
 // Sort sorts an ErrorList. *Error entries are sorted by position,