github.com/kaiya/goutils@v1.0.1-0.20230226104005-4ae4a4dc3688/slicemap/slicemap.go (about) 1 package slicemap 2 3 type kv struct { 4 k []byte 5 v []byte 6 } 7 8 type sliceMap []kv 9 10 // zero alloc 11 func (sm *sliceMap) Add(k, v []byte) { 12 kvs := *sm 13 if cap(kvs) > len(kvs) { 14 kvs = kvs[:len(kvs)+1] 15 } else { 16 kvs = append(kvs, kv{}) 17 } 18 kv := &kvs[len(kvs)-1] 19 kv.k = append(kv.k[:0], k...) 20 kv.v = append(kv.v[:0], v...) 21 *sm = kvs 22 }