]> Cypherpunks repositories - gostls13.git/commitdiff
go/printer: clearer logic (clenaup)
authorRobert Griesemer <gri@golang.org>
Mon, 2 Feb 2015 19:02:09 +0000 (11:02 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 2 Feb 2015 19:11:12 +0000 (19:11 +0000)
Change-Id: I278ce47b38ec5732d981aec06b71f9ee5747c3bb
Reviewed-on: https://go-review.googlesource.com/3730
Reviewed-by: Alan Donovan <adonovan@google.com>
src/go/printer/printer.go

index 5160757e142aceab954daf7af888df7360a9244c..36f9439a284be4cdcba7d1df3a7ecdfbe5b4074e 100644 (file)
@@ -504,26 +504,25 @@ func stripCommonPrefix(lines []string) {
        // Note that the first and last line are never empty (they
        // contain the opening /* and closing */ respectively) and
        // thus they can be ignored by the blank line check.
-       var prefix string
+       prefix := ""
+       prefixSet := false
        if len(lines) > 2 {
-               first := true
                for i, line := range lines[1 : len(lines)-1] {
-                       switch {
-                       case isBlank(line):
+                       if isBlank(line) {
                                lines[1+i] = "" // range starts with lines[1]
-                       case first:
-                               prefix = commonPrefix(line, line)
-                               first = false
-                       default:
+                       } else {
+                               if !prefixSet {
+                                       prefix = line
+                                       prefixSet = true
+                               }
                                prefix = commonPrefix(prefix, line)
                        }
+
                }
-               if first { // all lines were blank (except first and last)
-                       line := lines[len(lines)-1]
-                       prefix = commonPrefix(line, line)
-               }
-       } else { // len(lines) == 2, lines cannot be blank (contain /* and */)
-               line := lines[1]
+       }
+       // If we don't have a prefix yet, consider the last line.
+       if !prefixSet {
+               line := lines[len(lines)-1]
                prefix = commonPrefix(line, line)
        }