Skip to content

Commit

Permalink
preallocate kline window with capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Nov 21, 2021
1 parent 540722e commit 20f0e8d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/bbgo/marketdatastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ func (store *MarketDataStore) handleKLineClosed(kline types.KLine) {
func (store *MarketDataStore) AddKLine(kline types.KLine) {
window, ok := store.KLineWindows[kline.Interval]
if !ok {
window = types.KLineWindow{kline}
} else {
window.Add(kline)
window = make(types.KLineWindow, 0, 1000)
}
window.Add(kline)

if len(window) > MaxNumOfKLines {
window = window[MaxNumOfKLinesTruncate-1:]
Expand Down

0 comments on commit 20f0e8d

Please sign in to comment.