Optimize memory allocation of the apat algorithms

Former-commit-id: 5010c5a666b322715b3b81c1078d325e1f647ede
This commit is contained in:
2023-03-28 19:37:05 +07:00
parent 21819cd41e
commit 988ae79989
19 changed files with 117 additions and 180 deletions

View File

@@ -20,7 +20,9 @@ func RecycleSlice(s *[]byte) {
if cap(*s) == 0 {
log.Panicln("trying to store a NIL slice in the pool", s == nil, *s == nil, cap(*s))
}
_BioSequenceByteSlicePool.Put(s)
if cap(*s) <= 1024 {
_BioSequenceByteSlicePool.Put(s)
}
}
}
@@ -28,7 +30,10 @@ func RecycleSlice(s *[]byte) {
//
// the slice can be prefilled with the provided values
func GetSlice(capacity int) []byte {
p := _BioSequenceByteSlicePool.Get().(*[]byte)
p := (*[]byte)(nil)
if capacity <= 1024 {
p = _BioSequenceByteSlicePool.Get().(*[]byte)
}
if p == nil || *p == nil || cap(*p) < capacity {
s := make([]byte, 0, capacity)