Skip to content

Commit 9aa9a65

Browse files
authored
Merge pull request #20 from pipelined/allocator-length
Add length to allocator
2 parents 345a669 + dd5d4d4 commit 9aa9a65

24 files changed

+131
-154
lines changed

example_read_write_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func Example_readWrite() {
2222
signal.ReadInt(buf, output) // read data into output
2323
fmt.Println(output)
2424

25-
output = make([]int, 16) // reset output
26-
signal.ReadInt(buf.Reset(), output) // reset buffer length to 0 and read data into output
25+
output = make([]int, 16) // reset output
26+
signal.ReadInt(buf.Slice(0, 0), output) // reset buffer length to 0 and read data into output
2727
fmt.Println(output)
2828

2929
// Output:

float32.go

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

float32_test.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

float64.go

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

float64_test.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen.go

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ var (
134134
)
135135

136136
const (
137-
floating = `// Code generated by go generate; DO NOT EDIT.
137+
floating = `package signal
138+
139+
// Code generated by go generate; DO NOT EDIT.
138140
// This file was generated by robots at
139141
// {{ .Timestamp }}
140-
package signal
141142
142143
import "math"
143144
@@ -150,7 +151,7 @@ type {{ .Name }} struct {
150151
// {{ .Name }} allocates a new sequential {{ .Builtin }} signal buffer.
151152
func (a Allocator) {{ .Name }}() Floating {
152153
return {{ .Name }}{
153-
buffer: make([]{{ .Builtin }}, 0, a.Channels*a.Capacity),
154+
buffer: make([]{{ .Builtin }}, a.Channels*a.Length, a.Channels*a.Capacity),
154155
channels: channels(a.Channels),
155156
}
156157
}
@@ -175,7 +176,7 @@ func (p *Pool) Put{{ .Name }}(s Floating) {
175176
panic("pool put {{ .Builtin }} invalid type")
176177
}
177178
mustSameCapacity(s.Capacity(), p.allocator.Capacity)
178-
p.{{ .Pool }}.Put(s.Reset())
179+
p.{{ .Pool }}.Put(s.Slice(0, p.allocator.Length))
179180
}
180181
181182
@@ -233,11 +234,6 @@ func (s {{ .Name }}) Slice(start, end int) Floating {
233234
return s
234235
}
235236
236-
// Reset sets length of the buffer to zero.
237-
func (s {{ .Name }}) Reset() Floating {
238-
return s.Slice(0, 0)
239-
}
240-
241237
// Append appends data from src buffer to the end of the buffer.
242238
func (s {{ .Name }}) Append(src Floating) Floating {
243239
mustSameChannels(s.Channels(), src.Channels())
@@ -307,10 +303,11 @@ func WriteStriped{{ .Name }}(src [][]{{ .Builtin }}, dst Floating) Floating {
307303
return dst
308304
}`
309305

310-
signed = `// Code generated by go generate; DO NOT EDIT.
306+
signed = `package signal
307+
308+
// Code generated by go generate; DO NOT EDIT.
311309
// This file was generated by robots at
312310
// {{ .Timestamp }}
313-
package signal
314311
315312
import "math"
316313
@@ -324,7 +321,7 @@ type {{ .Name }} struct {
324321
// {{ .Name }} allocates a new sequential {{ .Builtin }} signal buffer.
325322
func (a Allocator) {{ .Name }}(bd BitDepth) Signed {
326323
return {{ .Name }}{
327-
buffer: make([]{{ .Builtin }}, 0, a.Capacity*a.Channels),
324+
buffer: make([]{{ .Builtin }}, a.Channels*a.Length, a.Capacity*a.Channels),
328325
channels: channels(a.Channels),
329326
bitDepth: limitBitDepth(bd, {{ .MaxBitDepth }}),
330327
}
@@ -350,7 +347,7 @@ func (p *Pool) Put{{ .Name }}(s Signed) {
350347
panic("pool put {{ .Builtin }} invalid type")
351348
}
352349
mustSameCapacity(s.Capacity(), p.allocator.Capacity)
353-
p.{{ .Pool }}.Put(s.Reset())
350+
p.{{ .Pool }}.Put(s.Slice(0, p.allocator.Length))
354351
}
355352
356353
func (s {{ .Name }}) setBitDepth(bd BitDepth) Signed {
@@ -412,11 +409,6 @@ func (s {{ .Name }}) Slice(start, end int) Signed {
412409
return s
413410
}
414411
415-
// Reset sets length of the buffer to zero.
416-
func (s {{ .Name }}) Reset() Signed {
417-
return s.Slice(0, 0)
418-
}
419-
420412
// Append appends [0:Length] data from src to current buffer and returns new
421413
// Signed buffer. Both buffers must have same number of channels and bit depth,
422414
// otherwise function will panic. If current buffer doesn't have enough capacity,
@@ -494,10 +486,11 @@ func WriteStriped{{ .Name }}(src [][]{{ .Builtin }}, dst Signed) Signed {
494486
}
495487
`
496488

497-
unsigned = `// Code generated by go generate; DO NOT EDIT.
489+
unsigned = `package signal
490+
491+
// Code generated by go generate; DO NOT EDIT.
498492
// This file was generated by robots at
499493
// {{ .Timestamp }}
500-
package signal
501494
502495
import "math"
503496
@@ -511,7 +504,7 @@ type {{ .Name }} struct {
511504
// {{ .Name }} allocates a new sequential {{ .Builtin }} signal buffer.
512505
func (a Allocator) {{ .Name }}(bd BitDepth) Unsigned {
513506
return {{ .Name }}{
514-
buffer: make([]{{ .Builtin }}, 0, a.Capacity*a.Channels),
507+
buffer: make([]{{ .Builtin }}, a.Channels*a.Length, a.Capacity*a.Channels),
515508
channels: channels(a.Channels),
516509
bitDepth: limitBitDepth(bd, BitDepth64),
517510
}
@@ -537,7 +530,7 @@ func (p *Pool) Put{{ .Name }}(s Unsigned) {
537530
panic("pool put {{ .Builtin }} invalid type")
538531
}
539532
mustSameCapacity(s.Capacity(), p.allocator.Capacity)
540-
p.{{ .Pool }}.Put(s.Reset())
533+
p.{{ .Pool }}.Put(s.Slice(0, p.allocator.Length))
541534
}
542535
543536
func (s {{ .Name }}) setBitDepth(bd BitDepth) Unsigned {
@@ -599,11 +592,6 @@ func (s {{ .Name }}) Slice(start, end int) Unsigned {
599592
return s
600593
}
601594
602-
// Reset sets length of the buffer to zero.
603-
func (s {{ .Name }}) Reset() Unsigned {
604-
return s.Slice(0, 0)
605-
}
606-
607595
// Append appends data from src to current buffer and returns new
608596
// Unsigned buffer. Both buffers must have same number of channels and bit depth,
609597
// otherwise function will panic. If current buffer doesn't have enough capacity,
@@ -680,10 +668,11 @@ func WriteStriped{{ .Name }}(src [][]{{ .Builtin }}, dst Unsigned) Unsigned {
680668
return dst
681669
}`
682670

683-
fixedTests = `// Code generated by go generate; DO NOT EDIT.
671+
fixedTests = `package signal_test
672+
673+
// Code generated by go generate; DO NOT EDIT.
684674
// This file was generated by robots at
685675
// {{ .Timestamp }}
686-
package signal_test
687676
688677
import (
689678
"testing"
@@ -720,10 +709,11 @@ func Test{{ .Name }}(t *testing.T) {
720709
},
721710
))
722711
}`
723-
floatingTests = `// Code generated by go generate; DO NOT EDIT.
712+
floatingTests = `package signal_test
713+
714+
// Code generated by go generate; DO NOT EDIT.
724715
// This file was generated by robots at
725716
// {{ .Timestamp }}
726-
package signal_test
727717
728718
import (
729719
"testing"

int16.go

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

int16_test.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

int32.go

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

int32_test.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)