aboutsummaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorJes Cok <xigua67damn@gmail.com>2023-10-07 16:18:16 +0000
committerGopher Robot <gobot@golang.org>2023-10-09 21:56:00 +0000
commit5955a03e9c22c56fa3d174e95031d74e2cf3adde (patch)
tree19ae9a156c1651ebe1235f3bbb7d83b52ec83d2a /src/reflect
parent5da31049a633e225c2fc9d3500c162f87651ceef (diff)
downloadgo-5955a03e9c22c56fa3d174e95031d74e2cf3adde.tar.gz
go-5955a03e9c22c56fa3d174e95031d74e2cf3adde.zip
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: cbfba7ee9ab0a0bda371db3ad5e8cc4d5ea91579 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>
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/type.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/reflect/type.go b/src/reflect/type.go
index d6744c2898..a35898547a 100644
--- a/src/reflect/type.go
+++ b/src/reflect/type.go
@@ -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