Reducing memory allocation events

Former-commit-id: c94e79ba116464504580fc397270ead154063971
This commit is contained in:
Eric Coissac
2024-06-22 22:32:31 +02:00
parent e6b87ecd02
commit 93f9dcb95f
8 changed files with 98 additions and 46 deletions

View File

@ -1,8 +1,10 @@
package obiformats
import (
"bytes"
"math"
"strings"
"unsafe"
log "github.com/sirupsen/logrus"
@ -85,17 +87,26 @@ func ParseFastSeqJsonHeader(sequence *obiseq.BioSequence) {
}
}
func FormatFastSeqJsonHeader(sequence *obiseq.BioSequence) string {
func WriteFastSeqJsonHeader(buffer *bytes.Buffer, sequence *obiseq.BioSequence) {
annotations := sequence.Annotations()
if len(annotations) > 0 {
text, err := obiutils.JsonMarshal(sequence.Annotations())
err := obiutils.JsonMarshalByteBuffer(buffer, sequence.Annotations())
if err != nil {
log.Fatal(err)
}
}
}
return string(text)
func FormatFastSeqJsonHeader(sequence *obiseq.BioSequence) string {
annotations := sequence.Annotations()
buffer := bytes.Buffer{}
if len(annotations) > 0 {
obiutils.JsonMarshalByteBuffer(&buffer, sequence.Annotations())
return unsafe.String(unsafe.SliceData(buffer.Bytes()), len(buffer.Bytes()))
}
return ""