reflect: add Cap and Len support for map and chan

This commit is contained in:
cornelk
2020-05-11 20:55:20 +03:00
committed by Ayke
parent 7e64bc8f77
commit 2c71f08922
2 changed files with 34 additions and 8 deletions
+8 -1
View File
@@ -1,7 +1,7 @@
package runtime
// This is a hashmap implementation for the map[T]T type.
// It is very rougly based on the implementation of the Go hashmap:
// It is very roughly based on the implementation of the Go hashmap:
//
// https://golang.org/src/runtime/map.go
@@ -80,6 +80,7 @@ func hashmapMake(keySize, valueSize uint8, sizeHint uintptr) *hashmap {
// Return the number of entries in this hashmap, called from the len builtin.
// A nil hashmap is defined as having length 0.
//go:inline
func hashmapLen(m *hashmap) int {
if m == nil {
return 0
@@ -87,6 +88,12 @@ func hashmapLen(m *hashmap) int {
return int(m.count)
}
// wrapper for use in reflect
func hashmapLenUnsafePointer(p unsafe.Pointer) int {
m := (*hashmap)(p)
return hashmapLen(m)
}
// Set a specified key to a given value. Grow the map if necessary.
//go:nobounds
func hashmapSet(m *hashmap, key unsafe.Pointer, value unsafe.Pointer, hash uint32, keyEqual func(x, y unsafe.Pointer, n uintptr) bool) {