-
Notifications
You must be signed in to change notification settings - Fork 13
/
map.go
67 lines (55 loc) · 1.38 KB
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package jettison
import (
"bytes"
"sync"
"unsafe"
)
var (
hiterPool sync.Pool // *hiter
mapElemsPool sync.Pool // *mapElems
)
// kv represents a map key/value pair.
type kv struct {
key []byte
keyval []byte
}
type mapElems struct{ s []kv }
// releaseMapElems zeroes the content of the
// map elements slice and resets the length to
// zero before putting it back to the pool.
func releaseMapElems(me *mapElems) {
for i := range me.s {
me.s[i] = kv{}
}
me.s = me.s[:0]
mapElemsPool.Put(me)
}
func (m mapElems) Len() int { return len(m.s) }
func (m mapElems) Swap(i, j int) { m.s[i], m.s[j] = m.s[j], m.s[i] }
func (m mapElems) Less(i, j int) bool { return bytes.Compare(m.s[i].key, m.s[j].key) < 0 }
// hiter is the runtime representation
// of a hashmap iteration structure.
type hiter struct {
key unsafe.Pointer
val unsafe.Pointer
// remaining fields are ignored but
// present in the struct so that it
// can be zeroed for reuse.
// see hiter in src/runtime/map.go
_ [6]unsafe.Pointer
_ uintptr
_ uint8
_ bool
_ [2]uint8
_ [2]uintptr
}
var zeroHiter = &hiter{}
//go:noescape
//go:linkname mapiterinit runtime.mapiterinit
func mapiterinit(unsafe.Pointer, unsafe.Pointer, unsafe.Pointer)
//go:noescape
//go:linkname mapiternext reflect.mapiternext
func mapiternext(*hiter)
//go:noescape
//go:linkname maplen reflect.maplen
func maplen(unsafe.Pointer) int