Files
obitools4/pkg/obiseq/pool.go

62 lines
967 B
Go
Raw Normal View History

2022-01-13 23:27:39 +01:00
package obiseq
import (
"sync"
2022-01-16 00:21:42 +01:00
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
2022-01-13 23:27:39 +01:00
)
2022-01-16 00:21:42 +01:00
var _BioSequenceByteSlicePool = sync.Pool{
2022-01-13 23:27:39 +01:00
New: func() interface{} {
2022-01-16 00:21:42 +01:00
bs := make([]byte, 0, 300)
2022-01-13 23:27:39 +01:00
return &bs
},
}
2022-02-18 22:53:09 +01:00
func RecycleSlice(s *[]byte) {
if s != nil && *s != nil {
*s = (*s)[:0]
_BioSequenceByteSlicePool.Put(s)
}
2022-01-16 00:21:42 +01:00
}
func GetSlice(values ...byte) []byte {
s := *(_BioSequenceByteSlicePool.Get().(*[]byte))
if len(values) > 0 {
s = append(s, values...)
}
return s
}
var BioSequenceAnnotationPool = sync.Pool{
New: func() interface{} {
bs := make(Annotation, 5)
2022-01-16 00:21:42 +01:00
return &bs
},
2022-01-13 23:27:39 +01:00
}
2022-02-18 22:53:09 +01:00
func RecycleAnnotation(a *Annotation) {
2022-02-01 17:31:28 +01:00
if a != nil {
2022-02-18 22:53:09 +01:00
for k := range *a {
delete(*a, k)
2022-02-01 17:31:28 +01:00
}
BioSequenceAnnotationPool.Put(a)
2022-01-16 00:21:42 +01:00
}
2022-01-13 23:27:39 +01:00
}
2022-01-16 00:21:42 +01:00
func GetAnnotation(values ...Annotation) Annotation {
a := Annotation(nil)
2022-01-16 00:21:42 +01:00
for a == nil {
a = *(BioSequenceAnnotationPool.Get().(*Annotation))
2022-01-16 00:21:42 +01:00
}
2022-02-18 22:53:09 +01:00
if len(values) > 0 {
goutils.CopyMap(a, values[0])
2022-02-18 22:53:09 +01:00
}
return a
2022-02-18 22:53:09 +01:00
}