Use slices.Clone instead of copy()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-12-12 18:36:59 +01:00
parent 029e2fe619
commit 6476c8414b
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
4 changed files with 8 additions and 5 deletions

2
go.mod
View file

@ -1,3 +1,5 @@
module git.gammaspectra.live/S.O.N.G/goborator
go 1.18
require golang.org/x/exp v0.0.0-20221212164502-fae10dda9338

2
go.sum
View file

@ -0,0 +1,2 @@
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338 h1:OvjRkcNHnf6/W5FZXSxODbxwD+X7fspczG7Jn/xQVD4=
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=

View file

@ -7,6 +7,7 @@ package goborator
import "C"
import (
"fmt"
"golang.org/x/exp/slices"
"log"
"runtime"
"unsafe"
@ -159,8 +160,7 @@ func (g *Gaborator) analyze(block []float32) {
}
func (g *Gaborator) outputResult(block []float32, sliceSize int) {
buf := make([]float32, len(block))
copy(buf, block)
buf := slices.Clone(block)
for i := 0; i < len(block); i += sliceSize {
g.coefficientOutputChannel <- buf[i : i+sliceSize]

View file

@ -2,6 +2,7 @@ package goborator
import (
"fmt"
"golang.org/x/exp/slices"
"os"
"testing"
"time"
@ -29,9 +30,7 @@ func TestGoborator(t *testing.T) {
n, err := file.Read(buf)
if n > 4 {
values := make([]float32, n/4)
copy(values, unsafe.Slice((*float32)(unsafe.Pointer(&buf[0])), n/4))
channel <- values
channel <- slices.Clone(unsafe.Slice((*float32)(unsafe.Pointer(&buf[0])), n/4))
}
if err != nil {
return