From b5f87b5407916c4049a3158cc944cebfd7a883a9 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Tue, 10 Oct 2023 12:43:40 +0000 Subject: runtime: use max/min func Change-Id: I3f0b7209621b39cee69566a5cc95e4343b4f1f20 GitHub-Last-Rev: af9dbbe69ad74e8c210254dafa260a886b690853 GitHub-Pull-Request: golang/go#63321 Reviewed-on: https://go-review.googlesource.com/c/go/+/531916 LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Mauri de Souza Meneguzzo Reviewed-by: Dmitri Shuralyov Reviewed-by: Keith Randall --- src/runtime/mpallocbits.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/runtime/mpallocbits.go') diff --git a/src/runtime/mpallocbits.go b/src/runtime/mpallocbits.go index 2f35ce007c..6b5f15dbd8 100644 --- a/src/runtime/mpallocbits.go +++ b/src/runtime/mpallocbits.go @@ -134,7 +134,7 @@ type pallocBits pageBits // summarize returns a packed summary of the bitmap in pallocBits. func (b *pallocBits) summarize() pallocSum { - var start, max, cur uint + var start, most, cur uint const notSetYet = ^uint(0) // sentinel for start value start = notSetYet for i := 0; i < len(b); i++ { @@ -151,9 +151,7 @@ func (b *pallocBits) summarize() pallocSum { if start == notSetYet { start = cur } - if cur > max { - max = cur - } + most = max(most, cur) // Final region that might span to next uint64 cur = l } @@ -162,12 +160,11 @@ func (b *pallocBits) summarize() pallocSum { const n = uint(64 * len(b)) return packPallocSum(n, n, n) } - if cur > max { - max = cur - } - if max >= 64-2 { + most = max(most, cur) + + if most >= 64-2 { // There is no way an internal run of zeros could beat max. - return packPallocSum(start, max, cur) + return packPallocSum(start, most, cur) } // Now look inside each uint64 for runs of zeros. // All uint64s must be nonzero, or we would have aborted above. @@ -188,7 +185,7 @@ outer: // Strategy: shrink all runs of zeros by max. If any runs of zero // remain, then we've identified a larger maximum zero run. - p := max // number of zeros we still need to shrink by. + p := most // number of zeros we still need to shrink by. k := uint(1) // current minimum length of runs of ones in x. for { // Shrink all runs of zeros by p places (except the top zeros). @@ -217,14 +214,14 @@ outer: x >>= j & 63 // remove trailing ones j = uint(sys.TrailingZeros64(x)) // count contiguous trailing zeros x >>= j & 63 // remove zeros - max += j // we have a new maximum! + most += j // we have a new maximum! if x&(x+1) == 0 { // no more zeros (except at the top). continue outer } p = j // remove j more zeros from each zero run. } } - return packPallocSum(start, max, cur) + return packPallocSum(start, most, cur) } // find searches for npages contiguous free pages in pallocBits and returns -- cgit v1.3