mirror of https://github.com/golang/go.git
net: avoid array copy when shuffling SRV records
We don't need to shift array elements to shuffle them. We just have to swap a selected element with 0th element. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/91750044
This commit is contained in:
parent
60c0b3b5cf
commit
38eea5b2ad
|
|
@ -196,9 +196,7 @@ func (addrs byPriorityWeight) shuffleByWeight() {
|
|||
s += int(addrs[i].Weight)
|
||||
if s > n {
|
||||
if i > 0 {
|
||||
t := addrs[i]
|
||||
copy(addrs[1:i+1], addrs[0:i])
|
||||
addrs[0] = t
|
||||
addrs[0], addrs[i] = addrs[i], addrs[0]
|
||||
}
|
||||
break
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue