]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: shift the index for the sort by one.
authorAdam Langley <agl@golang.org>
Fri, 4 Dec 2009 21:31:18 +0000 (13:31 -0800)
committerAdam Langley <agl@golang.org>
Fri, 4 Dec 2009 21:31:18 +0000 (13:31 -0800)
Makes the code look cleaner, even if it's a little harder to figure
out from the sort invariants.

R=rsc
CC=golang-dev
https://golang.org/cl/165061

src/pkg/runtime/chan.c

index 1eef4b1cfaf4d384e3506c924b5d8c69b93e8307..633ff426e883f30bdf5638ec7437341e4f072cf0 100644 (file)
@@ -660,12 +660,8 @@ runtime·selectgo(Select *sel)
        // sort the cases by Hchan address to get the locking order.
        for(i=1; i<sel->ncase; i++) {
                cas = sel->scase[i];
-               for(j=i-1; j<i && sel->scase[j]->chan >= cas->chan; j--)
-                       sel->scase[j+1] = sel->scase[j];
-               // careful: j might be (unsigned)-1
-               // 6c trips on sel->scase[j+1] in that case by rewriting it to
-               // sel->scase[j] + 8.
-               j++;
+               for(j=i; j>0 && sel->scase[j-1]->chan >= cas->chan; j--)
+                       sel->scase[j] = sel->scase[j-1];
                sel->scase[j] = cas;
        }