Skip to content

Commit 6ba0be1

Browse files
committed
hash/maphash: mark call into runtime hash function as not escaping
This allows maphash.Hash to be allocated on the stack for typical uses. Fixes #35636 Change-Id: I8366507d26ea717f47a9fb46d3bd69ba799845ac Reviewed-on: https://go-review.googlesource.com/c/go/+/207444 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent c20b71e commit 6ba0be1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/hash/maphash/maphash.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func rthash(b []byte, seed uint64) uint64 {
193193
}
194194

195195
//go:linkname runtime_memhash runtime.memhash
196+
//go:noescape
196197
func runtime_memhash(p unsafe.Pointer, seed, s uintptr) uintptr
197198

198199
// Sum appends the hash's current 64-bit value to b.

test/escape_hash_maphash.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// errorcheck -0 -m -l
2+
3+
// Copyright 2019 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Test escape analysis for hash/maphash.
8+
9+
package escape
10+
11+
import (
12+
"hash/maphash"
13+
)
14+
15+
func f() {
16+
var x maphash.Hash // should be stack allocatable
17+
x.WriteString("foo")
18+
x.Sum64()
19+
}

0 commit comments

Comments
 (0)