Use slices.Clone instead of copy()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
029e2fe619
commit
6476c8414b
2
go.mod
2
go.mod
|
@ -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
2
go.sum
|
@ -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=
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue