Commit 38eea5b2 authored by Rui Ueyama's avatar Rui Ueyama

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
parent 60c0b3b5
...@@ -196,9 +196,7 @@ func (addrs byPriorityWeight) shuffleByWeight() { ...@@ -196,9 +196,7 @@ func (addrs byPriorityWeight) shuffleByWeight() {
s += int(addrs[i].Weight) s += int(addrs[i].Weight)
if s > n { if s > n {
if i > 0 { if i > 0 {
t := addrs[i] addrs[0], addrs[i] = addrs[i], addrs[0]
copy(addrs[1:i+1], addrs[0:i])
addrs[0] = t
} }
break break
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment