diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-01-17 10:28:16 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-01-17 10:02:07 +0000 |
| commit | 5d04aae8969f6c72318ce0a4cde4f027766b1a55 (patch) | |
| tree | 8f1b632847c431407090f0fe1335522ff2195a37 /pkg/cover | |
| parent | f9e07a6e597b68d3397864e6ee4550f9065c3518 (diff) | |
all: use min/max functions
They are shorter, more readable, and don't require temp vars.
Diffstat (limited to 'pkg/cover')
| -rw-r--r-- | pkg/cover/backend/dwarf.go | 18 | ||||
| -rw-r--r-- | pkg/cover/html.go | 19 |
2 files changed, 8 insertions, 29 deletions
diff --git a/pkg/cover/backend/dwarf.go b/pkg/cover/backend/dwarf.go index 375a82dcc..eeb924a4b 100644 --- a/pkg/cover/backend/dwarf.go +++ b/pkg/cover/backend/dwarf.go @@ -405,21 +405,14 @@ func readTextRanges(debugInfo *dwarf.Data, module *vminfo.KernelModule, pcFix pc func symbolizeModule(target *targets.Target, interner *symbolizer.Interner, objDir, srcDir, buildDir string, splitBuildDelimiters []string, mod *vminfo.KernelModule, pcs []uint64) ([]Frame, error) { - procs := runtime.GOMAXPROCS(0) / 2 - if need := len(pcs) / 1000; procs > need { - procs = need - } + procs := min(runtime.GOMAXPROCS(0)/2, len(pcs)/1000) const ( minProcs = 1 maxProcs = 4 ) // addr2line on a beefy vmlinux takes up to 1.6GB of RAM, so don't create too many of them. - if procs > maxProcs { - procs = maxProcs - } - if procs < minProcs { - procs = minProcs - } + procs = min(procs, maxProcs) + procs = max(procs, minProcs) type symbolizerResult struct { frames []symbolizer.Frame err error @@ -449,10 +442,7 @@ func symbolizeModule(target *targets.Target, interner *symbolizer.Interner, objD }() } for i := 0; i < len(pcs); { - end := i + 100 - if end > len(pcs) { - end = len(pcs) - } + end := min(i+100, len(pcs)) pcchan <- pcs[i:end] i = end } diff --git a/pkg/cover/html.go b/pkg/cover/html.go index ba38cd884..2c8a1281e 100644 --- a/pkg/cover/html.go +++ b/pkg/cover/html.go @@ -160,10 +160,7 @@ func fileLineContents(file *file, lines [][]byte) lineCoverExport { start := 0 cover := append(lineCover[i+1], lineCoverChunk{End: backend.LineEnd}) for _, cov := range cover { - end := cov.End - 1 - if end > len(ln) { - end = len(ln) - } + end := min(cov.End-1, len(ln)) if end == start { continue } @@ -661,10 +658,7 @@ func fileContents(file *file, lines [][]byte, haveProgs bool) string { start := 0 cover := append(lineCover[i+1], lineCoverChunk{End: backend.LineEnd}) for _, cov := range cover { - end := cov.End - 1 - if end > len(ln) { - end = len(ln) - } + end := min(cov.End-1, len(ln)) if end == start { continue } @@ -708,9 +702,7 @@ func perLineCoverage(covered, uncovered []backend.Range) map[int][]lineCoverChun func mergeRange(lines map[int][]lineCoverChunk, r backend.Range, covered bool) { // Don't panic on broken debug info, it is frequently broken. - if r.EndLine < r.StartLine { - r.EndLine = r.StartLine - } + r.EndLine = max(r.EndLine, r.StartLine) if r.EndLine == r.StartLine && r.EndCol <= r.StartCol { r.EndCol = backend.LineEnd } @@ -750,10 +742,7 @@ func mergeLine(chunks []lineCoverChunk, start, end int, covered bool) []lineCove if chunkStart < start { res = append(res, lineCoverChunk{start, chunk.Covered, chunk.Uncovered}) } - mid := end - if mid > chunk.End { - mid = chunk.End - } + mid := min(end, chunk.End) res = append(res, lineCoverChunk{mid, chunk.Covered || covered, chunk.Uncovered || !covered}) if chunk.End > end { res = append(res, lineCoverChunk{chunk.End, chunk.Covered, chunk.Uncovered}) |
