From 6cf530065029c13cd416c608fadeec84456514ed Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 8 Jul 2021 10:28:49 +0800 Subject: [PATCH] max: preallocate fastjson array object var memory --- pkg/exchange/max/maxapi/public_parser.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/exchange/max/maxapi/public_parser.go b/pkg/exchange/max/maxapi/public_parser.go index 8c0adcc7b..95f88c87b 100644 --- a/pkg/exchange/max/maxapi/public_parser.go +++ b/pkg/exchange/max/maxapi/public_parser.go @@ -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)