mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 13:41:47 +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) {
|
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
|
||||||
|
|
Loading…
Reference in a new issue