Skip to content

Commit d851a44

Browse files
committed
Replace pool with bytes in readLoop
Replace pool with bytes in readLoop
1 parent a9e88d2 commit d851a44

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

datachannel.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,11 @@ func (d *DataChannel) onError(err error) {
349349
}
350350
}
351351

352-
// See https://github.com/pion/webrtc/issues/1516
353-
// nolint:gochecknoglobals
354-
var rlBufPool = sync.Pool{New: func() interface{} {
355-
return make([]byte, dataChannelBufferSize)
356-
}}
357-
358352
func (d *DataChannel) readLoop() {
353+
buffer := make([]byte, dataChannelBufferSize)
359354
for {
360-
buffer := rlBufPool.Get().([]byte) //nolint:forcetypeassert
361355
n, isString, err := d.dataChannel.ReadDataChannel(buffer)
362356
if err != nil {
363-
rlBufPool.Put(buffer) // nolint:staticcheck
364357
d.setReadyState(DataChannelStateClosed)
365358
if !errors.Is(err, io.EOF) {
366359
d.onError(err)
@@ -371,8 +364,6 @@ func (d *DataChannel) readLoop() {
371364

372365
m := DataChannelMessage{Data: make([]byte, n), IsString: isString}
373366
copy(m.Data, buffer[:n])
374-
// The 'staticcheck' pragma is a false positive on the part of the CI linter.
375-
rlBufPool.Put(buffer) // nolint:staticcheck
376367

377368
// NB: Why was DataChannelMessage not passed as a pointer value?
378369
d.onMessage(m) // nolint:staticcheck

0 commit comments

Comments
 (0)