Commit 3ffb8fd1 authored by Sameer Ajmani's avatar Sameer Ajmani

context: fix TestAllocs to account for ints in interfaces

Recent runtime changes mean that these are stored indirectly, requiring additional allocation.

LGTM=adonovan
R=rsc, bradfitz, adonovan
CC=golang-codereviews
https://golang.org/cl/148590043
parent 91e38aee
...@@ -142,27 +142,28 @@ var Canceled = errors.New("context canceled") ...@@ -142,27 +142,28 @@ var Canceled = errors.New("context canceled")
// deadline passes. // deadline passes.
var DeadlineExceeded = errors.New("context deadline exceeded") var DeadlineExceeded = errors.New("context deadline exceeded")
// An emptyCtx is never canceled, has no values, and has no deadline. // An emptyCtx is never canceled, has no values, and has no deadline. It is not
// struct{}, since vars of this type must have distinct addresses.
type emptyCtx int type emptyCtx int
func (emptyCtx) Deadline() (deadline time.Time, ok bool) { func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
return return
} }
func (emptyCtx) Done() <-chan struct{} { func (*emptyCtx) Done() <-chan struct{} {
return nil return nil
} }
func (emptyCtx) Err() error { func (*emptyCtx) Err() error {
return nil return nil
} }
func (emptyCtx) Value(key interface{}) interface{} { func (*emptyCtx) Value(key interface{}) interface{} {
return nil return nil
} }
func (n emptyCtx) String() string { func (e *emptyCtx) String() string {
switch n { switch e {
case background: case background:
return "context.Background" return "context.Background"
case todo: case todo:
...@@ -171,9 +172,9 @@ func (n emptyCtx) String() string { ...@@ -171,9 +172,9 @@ func (n emptyCtx) String() string {
return "unknown empty Context" return "unknown empty Context"
} }
const ( var (
background emptyCtx = 1 background = new(emptyCtx)
todo emptyCtx = 2 todo = new(emptyCtx)
) )
// Background returns a non-nil, empty Context. It is never canceled, has no // Background returns a non-nil, empty Context. It is never canceled, has no
......
...@@ -365,7 +365,7 @@ func TestAllocs(t *testing.T) { ...@@ -365,7 +365,7 @@ func TestAllocs(t *testing.T) {
c := WithValue(bg, k1, nil) c := WithValue(bg, k1, nil)
c.Value(k1) c.Value(k1)
}, },
limit: 1, limit: 3,
gccgoLimit: 3, gccgoLimit: 3,
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment