1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:51:37 -07:00

reflect: compute the median h uniformly

Like sort.Search, use "h := int(uint(i+j) >> 1)" to compute the median h.

Change-Id: I62c1e67533657e2b56af872676e5dc4ed4d49c55
GitHub-Last-Rev: cbfba7ee9a
GitHub-Pull-Request: golang/go#63439
Reviewed-on: https://go-review.googlesource.com/c/go/+/533595
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Jes Cok 2023-10-07 16:18:16 +00:00 committed by Gopher Robot
parent 5da31049a6
commit 5955a03e9c

View File

@ -1539,7 +1539,7 @@ func typesByString(s string) []*abi.Type {
// This is a copy of sort.Search, with f(h) replaced by (*typ[h].String() >= s).
i, j := 0, len(offs)
for i < j {
h := i + (j-i)>>1 // avoid overflow when computing h
h := int(uint(i+j) >> 1) // avoid overflow when computing h
// i ≤ h < j
if !(stringFor(rtypeOff(section, offs[h])) >= s) {
i = h + 1 // preserves f(i-1) == false