From: Josh Bleecher Snyder Date: Thu, 18 Dec 2014 19:48:39 +0000 (-0800) Subject: runtime: tighten select permutation generation X-Git-Tag: go1.5beta1~902 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fd5540e7e5d2149c723b2a636ceed32c1d534ff5;p=gostls13.git runtime: tighten select permutation generation This is the optimization made to math/rand in CL 21030043. Change-Id: I231b24fa77cac1fe74ba887db76313b5efaab3e8 Reviewed-on: https://go-review.googlesource.com/9269 Reviewed-by: Minux Ma --- diff --git a/src/runtime/select.go b/src/runtime/select.go index 2dd541b530..efe0ec8542 100644 --- a/src/runtime/select.go +++ b/src/runtime/select.go @@ -244,13 +244,9 @@ func selectgoImpl(sel *hselect) (uintptr, uint16) { pollslice := slice{unsafe.Pointer(sel.pollorder), int(sel.ncase), int(sel.ncase)} pollorder := *(*[]uint16)(unsafe.Pointer(&pollslice)) for i := 0; i < int(sel.ncase); i++ { - pollorder[i] = uint16(i) - } - for i := 1; i < int(sel.ncase); i++ { - o := pollorder[i] j := int(fastrand1()) % (i + 1) pollorder[i] = pollorder[j] - pollorder[j] = o + pollorder[j] = uint16(i) } // sort the cases by Hchan address to get the locking order.