github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/util/arenahelper/arenas_enabled.go (about) 1 //go:build goexperiment.arenas 2 3 package arenahelper 4 5 import "arena" 6 7 type ArenaWrapper *arena.Arena 8 9 func NewArenaWrapper() ArenaWrapper { 10 return arena.NewArena() 11 } 12 13 func Free(a ArenaWrapper) { 14 if a == nil { 15 return 16 } 17 (*arena.Arena)(a).Free() 18 } 19 20 func MakeSlice[T any](a ArenaWrapper, l, c int) []T { 21 if a == nil { 22 return make([]T, l, c) 23 } 24 return arena.MakeSlice[T](a, l, c) 25 } 26 27 func AppendA[T any](data []T, v T, a ArenaWrapper) []T { 28 if a == nil { 29 return append(data, v) 30 } 31 if len(data) >= cap(data) { 32 c := 2 * len(data) 33 if c == 0 { 34 c = 1 35 } 36 newData := arena.MakeSlice[T](a, len(data)+1, c) 37 copy(newData, data) 38 data = newData 39 data[len(data)-1] = v 40 } else { 41 data = append(data, v) 42 } 43 return data 44 }