mirror of
https://github.com/golang/go
synced 2024-11-17 00:44:46 -07:00
reflect: compute the median h uniformly
Like sort.Search, use "h := int(uint(i+j) >> 1)" style code to compute the median h.
This commit is contained in:
parent
f711892a8a
commit
cbfba7ee9a
@ -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).
|
// This is a copy of sort.Search, with f(h) replaced by (*typ[h].String() >= s).
|
||||||
i, j := 0, len(offs)
|
i, j := 0, len(offs)
|
||||||
for i < j {
|
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
|
// i ≤ h < j
|
||||||
if !(stringFor(rtypeOff(section, offs[h])) >= s) {
|
if !(stringFor(rtypeOff(section, offs[h])) >= s) {
|
||||||
i = h + 1 // preserves f(i-1) == false
|
i = h + 1 // preserves f(i-1) == false
|
||||||
|
Loading…
Reference in New Issue
Block a user