]> Cypherpunks repositories - gostls13.git/commitdiff
go/printer: use max/min func
authorqiulaidongfeng <2645477756@qq.com>
Sun, 1 Oct 2023 12:07:42 +0000 (12:07 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 2 Oct 2023 17:35:54 +0000 (17:35 +0000)
Change-Id: I2f708bca0c1e26fb63083731927d5d6a51d41690
GitHub-Last-Rev: 27d2000103d64c47b3c07e92f1d0bd16eadaeac2
GitHub-Pull-Request: golang/go#63320
Reviewed-on: https://go-review.googlesource.com/c/go/+/531915
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/go/printer/nodes.go
src/go/printer/printer.go

index e41ffc19583e4933407e900dce9a6e4dba7895ca..97c2cab0f840aed480ae5cd72c5085a078106d6f 100644 (file)
@@ -44,10 +44,7 @@ import (
 // linebreaks. At the moment there is no easy way to know about
 // future (not yet interspersed) comments in this function.
 func (p *printer) linebreak(line, min int, ws whiteSpace, newSection bool) (nbreaks int) {
-       n := nlimit(line - p.pos.Line)
-       if n < min {
-               n = min
-       }
+       n := max(nlimit(line-p.pos.Line), min)
        if n > 0 {
                p.print(ws)
                if newSection {
@@ -670,9 +667,7 @@ func walkBinary(e *ast.BinaryExpr) (has4, has5 bool, maxProblem int) {
                h4, h5, mp := walkBinary(l)
                has4 = has4 || h4
                has5 = has5 || h5
-               if maxProblem < mp {
-                       maxProblem = mp
-               }
+               maxProblem = max(maxProblem, mp)
        }
 
        switch r := e.Y.(type) {
@@ -685,9 +680,7 @@ func walkBinary(e *ast.BinaryExpr) (has4, has5 bool, maxProblem int) {
                h4, h5, mp := walkBinary(r)
                has4 = has4 || h4
                has5 = has5 || h5
-               if maxProblem < mp {
-                       maxProblem = mp
-               }
+               maxProblem = max(maxProblem, mp)
 
        case *ast.StarExpr:
                if e.Op == token.QUO { // `*/`
@@ -699,9 +692,7 @@ func walkBinary(e *ast.BinaryExpr) (has4, has5 bool, maxProblem int) {
                case "/*", "&&", "&^":
                        maxProblem = 5
                case "++", "--":
-                       if maxProblem < 4 {
-                               maxProblem = 4
-                       }
+                       maxProblem = max(maxProblem, 4)
                }
        }
        return
index 5cf4e4bb5fc25e910716a8ceb39f1b3bb098f62d..ff36d581402b4701a2c1b0eb8e51a36acf53842a 100644 (file)
@@ -861,10 +861,7 @@ func (p *printer) writeWhitespace(n int) {
 
 // nlimit limits n to maxNewlines.
 func nlimit(n int) int {
-       if n > maxNewlines {
-               n = maxNewlines
-       }
-       return n
+       return min(n, maxNewlines)
 }
 
 func mayCombine(prev token.Token, next byte) (b bool) {