Skip to content

Commit

Permalink
max: preallocate fastjson array object var memory
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jan 24, 2024
1 parent e67155d commit 6cf5300
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/exchange/max/maxapi/public_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,27 @@ func parseBookEvent(val *fastjson.Value) (event *BookEvent, err error) {
// parseBookEntries2 parses JSON struct like `[["233330", "0.33"], ....]`
func parseBookEntries2(vals []*fastjson.Value) (entries types.PriceVolumeSlice, err error) {
entries = make(types.PriceVolumeSlice, 0, 50)

var arr []*fastjson.Value
for _, entry := range vals {
arr, err := entry.Array()
arr, err = entry.Array()
if err != nil {
return nil, err
return entries, err
}

if len(arr) < 2 {
return nil, ErrIncorrectBookEntryElementLength
return entries, ErrIncorrectBookEntryElementLength
}

var pv types.PriceVolume
pv.Price, err = fixedpoint.NewFromString(string(arr[0].GetStringBytes()))
if err != nil {
return nil, err
return entries, err
}

pv.Volume, err = fixedpoint.NewFromString(string(arr[1].GetStringBytes()))
if err != nil {
return nil, err
return entries, err
}

entries = append(entries, pv)
Expand Down

0 comments on commit 6cf5300

Please sign in to comment.