mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
rpcsrv: microoptimize result allocation
We know the size. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
aefd0da181
commit
d22bdd8369
1 changed files with 6 additions and 5 deletions
|
@ -909,9 +909,10 @@ func (s *Server) getPeers(_ params.Params) (any, *neorpc.Error) {
|
|||
func (s *Server) getRawMempool(reqParams params.Params) (any, *neorpc.Error) {
|
||||
verbose, _ := reqParams.Value(0).GetBoolean()
|
||||
mp := s.chain.GetMemPool()
|
||||
hashList := make([]util.Uint256, 0)
|
||||
for _, item := range mp.GetVerifiedTransactions() {
|
||||
hashList = append(hashList, item.Hash())
|
||||
txes := mp.GetVerifiedTransactions()
|
||||
hashList := make([]util.Uint256, len(txes))
|
||||
for i := range txes {
|
||||
hashList[i] = txes[i].Hash()
|
||||
}
|
||||
if !verbose {
|
||||
return hashList, nil
|
||||
|
@ -2089,7 +2090,7 @@ func (s *Server) getCandidates(_ params.Params) (any, *neorpc.Error) {
|
|||
if err != nil {
|
||||
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 {
|
||||
res = append(res, result.Candidate{
|
||||
PublicKey: *v.Key,
|
||||
|
@ -2112,7 +2113,7 @@ func (s *Server) getNextBlockValidators(_ params.Params) (any, *neorpc.Error) {
|
|||
if err != nil {
|
||||
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 {
|
||||
if !validators.Contains(v.Key) {
|
||||
continue
|
||||
|
|
Loading…
Reference in a new issue