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:
Rui Ueyama 2014-06-16 18:00:28 -07:00
parent 60c0b3b5cf
commit 38eea5b2ad
1 changed files with 1 additions and 3 deletions

View File

@ -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
}