Skip to content

Commit c6a84fd

Browse files
authored
parsing: force min & max for automatic msgQueue size (#198)
1 parent e250686 commit c6a84fd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

parsing.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"math"
78
"sync"
89
"time"
910

@@ -62,14 +63,26 @@ func (p *Parser) ParseHeader() (common.DemoHeader, error) {
6263
// Initialize queue if the buffer size wasn't specified, the amount of ticks
6364
// seems to be a good indicator of how many events we'll get
6465
if p.msgQueue == nil {
65-
p.initMsgQueue(h.PlaybackTicks)
66+
p.initMsgQueue(msgQueueSize(h.PlaybackTicks))
6667
}
6768

6869
p.header = &h
6970

7071
return h, nil
7172
}
7273

74+
func msgQueueSize(ticks int) int {
75+
const (
76+
msgQueueMinSize = 50000
77+
msgQueueMaxSize = 500000
78+
)
79+
80+
size := math.Max(msgQueueMinSize, float64(ticks))
81+
size = math.Min(msgQueueMaxSize, size)
82+
83+
return int(size)
84+
}
85+
7386
// ParseToEnd attempts to parse the demo until the end.
7487
// Aborts and returns ErrCancelled if Cancel() is called before the end.
7588
//

0 commit comments

Comments
 (0)