mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: eliminate scase.kind field
Currently, we include a "kind" field on scase to distinguish the three kinds of cases in a select statement: sends, receives, and defaults. This commit removes by kind field by instead arranging for the compiler to always place sends before receives, and to provide their counts separately. It also passes an explicit "block bool" parameter to avoid needing to include a default case in the array. It's safe to shuffle cases like this because the runtime will randomize the order they're polled in anyway. Fixes #40410. Change-Id: Iaeaed4cf7bddd576d78f2c863bd91a03a5c82df2 Reviewed-on: https://go-review.googlesource.com/c/go/+/245125 Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
d36bc7d78a
commit
fe23ba4a14
5 changed files with 125 additions and 103 deletions
|
|
@ -1725,6 +1725,14 @@ func TestSelectMaxCases(t *testing.T) {
|
|||
_, _, _ = Select(sCases)
|
||||
}
|
||||
|
||||
func TestSelectNop(t *testing.T) {
|
||||
// "select { default: }" should always return the default case.
|
||||
chosen, _, _ := Select([]SelectCase{{Dir: SelectDefault}})
|
||||
if chosen != 0 {
|
||||
t.Fatalf("expected Select to return 0, but got %#v", chosen)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSelect(b *testing.B) {
|
||||
channel := make(chan int)
|
||||
close(channel)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue