1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:44:43 -07:00

go/printer: use max/min func

Change-Id: I2f708bca0c1e26fb63083731927d5d6a51d41690
GitHub-Last-Rev: 27d2000103
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>
This commit is contained in:
qiulaidongfeng 2023-10-01 12:07:42 +00:00 committed by Gopher Robot
parent c9c885f92f
commit a36070cbd5
2 changed files with 5 additions and 17 deletions

View File

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

View File

@ -861,10 +861,7 @@ func (p *printer) writeWhitespace(n int) {
// nlimit limits n to maxNewlines. // nlimit limits n to maxNewlines.
func nlimit(n int) int { func nlimit(n int) int {
if n > maxNewlines { return min(n, maxNewlines)
n = maxNewlines
}
return n
} }
func mayCombine(prev token.Token, next byte) (b bool) { func mayCombine(prev token.Token, next byte) (b bool) {