]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: tighten select permutation generation
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 18 Dec 2014 19:48:39 +0000 (11:48 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 27 Apr 2015 02:36:24 +0000 (02:36 +0000)
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 <minux@golang.org>
src/runtime/select.go

index 2dd541b530281916c73a13722c7b39cbbf4855a1..efe0ec8542ba04ced5d0b80872c00d49bf9a227d 100644 (file)
@@ -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.