]> Cypherpunks repositories - gostls13.git/commitdiff
net: avoid array copy when shuffling SRV records
authorRui Ueyama <ruiu@google.com>
Tue, 17 Jun 2014 01:00:28 +0000 (18:00 -0700)
committerRui Ueyama <ruiu@google.com>
Tue, 17 Jun 2014 01:00:28 +0000 (18:00 -0700)
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

src/pkg/net/dnsclient.go

index 9bffa11f9165df0a338cdd300fbd9c304225575a..e8014e4ffc961685290004eadb3253f1866a4ab3 100644 (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
                        }