mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
*: drop open-coded slice reversing
Less code, same performance. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
c7b623cc38
commit
7243754a0d
4 changed files with 5 additions and 15 deletions
|
@ -2,6 +2,7 @@ package core
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru/v2"
|
||||
|
@ -85,7 +86,7 @@ func (h *HeaderHashes) init(dao *dao.Simple) error {
|
|||
headers = append(headers, blk.Hash())
|
||||
hash = blk.PrevHash
|
||||
}
|
||||
hashSliceReverse(headers)
|
||||
slices.Reverse(headers)
|
||||
h.latest = append(h.latest, headers...)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -115,10 +115,3 @@ func getCommitteeAddress(committee []*keys.PublicKey) (val util.Uint160, err err
|
|||
}
|
||||
return hash.Hash160(raw), nil
|
||||
}
|
||||
|
||||
// hashSliceReverse reverses the given slice of util.Uint256.
|
||||
func hashSliceReverse(dest []util.Uint256) {
|
||||
for i, j := 0, len(dest)-1; i < j; i, j = i+1, j-1 {
|
||||
dest[i], dest[j] = dest[j], dest[i]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"slices"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
@ -293,9 +294,7 @@ func (s *Stack) ReverseTop(n int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
for i, j := l-n, l-1; i <= j; i, j = i+1, j-1 {
|
||||
s.elems[i], s.elems[j] = s.elems[j], s.elems[i]
|
||||
}
|
||||
slices.Reverse(s.elems[l-n : l])
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1352,10 +1352,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
if t.(stackitem.Immutable).IsReadOnly() {
|
||||
panic(stackitem.ErrReadOnly)
|
||||
}
|
||||
a := t.Value().([]stackitem.Item)
|
||||
for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
}
|
||||
slices.Reverse(t.Value().([]stackitem.Item))
|
||||
case *stackitem.Buffer:
|
||||
b := t.Value().([]byte)
|
||||
slices.Reverse(b)
|
||||
|
|
Loading…
Reference in a new issue