rpcsrv: microoptimize result allocation

We know the size.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2024-08-24 15:30:39 +03:00
parent aefd0da181
commit d22bdd8369

View file

@ -909,9 +909,10 @@ func (s *Server) getPeers(_ params.Params) (any, *neorpc.Error) {
func (s *Server) getRawMempool(reqParams params.Params) (any, *neorpc.Error) { func (s *Server) getRawMempool(reqParams params.Params) (any, *neorpc.Error) {
verbose, _ := reqParams.Value(0).GetBoolean() verbose, _ := reqParams.Value(0).GetBoolean()
mp := s.chain.GetMemPool() mp := s.chain.GetMemPool()
hashList := make([]util.Uint256, 0) txes := mp.GetVerifiedTransactions()
for _, item := range mp.GetVerifiedTransactions() { hashList := make([]util.Uint256, len(txes))
hashList = append(hashList, item.Hash()) for i := range txes {
hashList[i] = txes[i].Hash()
} }
if !verbose { if !verbose {
return hashList, nil return hashList, nil
@ -2089,7 +2090,7 @@ func (s *Server) getCandidates(_ params.Params) (any, *neorpc.Error) {
if err != nil { if err != nil {
return nil, neorpc.NewInternalServerError(fmt.Sprintf("Can't get enrollments: %s", err.Error())) return nil, neorpc.NewInternalServerError(fmt.Sprintf("Can't get enrollments: %s", err.Error()))
} }
var res = make([]result.Candidate, 0) var res = make([]result.Candidate, 0, len(enrollments))
for _, v := range enrollments { for _, v := range enrollments {
res = append(res, result.Candidate{ res = append(res, result.Candidate{
PublicKey: *v.Key, PublicKey: *v.Key,
@ -2112,7 +2113,7 @@ func (s *Server) getNextBlockValidators(_ params.Params) (any, *neorpc.Error) {
if err != nil { if err != nil {
return nil, neorpc.NewInternalServerError(fmt.Sprintf("Can't get enrollments: %s", err.Error())) return nil, neorpc.NewInternalServerError(fmt.Sprintf("Can't get enrollments: %s", err.Error()))
} }
var res = make([]result.Validator, 0) var res = make([]result.Validator, 0, len(validators))
for _, v := range enrollments { for _, v := range enrollments {
if !validators.Contains(v.Key) { if !validators.Contains(v.Key) {
continue continue