mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-18 11:15:36 +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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru/v2"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
|
@ -85,7 +86,7 @@ func (h *HeaderHashes) init(dao *dao.Simple) error {
|
||||||
headers = append(headers, blk.Hash())
|
headers = append(headers, blk.Hash())
|
||||||
hash = blk.PrevHash
|
hash = blk.PrevHash
|
||||||
}
|
}
|
||||||
hashSliceReverse(headers)
|
slices.Reverse(headers)
|
||||||
h.latest = append(h.latest, headers...)
|
h.latest = append(h.latest, headers...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -115,10 +115,3 @@ func getCommitteeAddress(committee []*keys.PublicKey) (val util.Uint160, err err
|
||||||
}
|
}
|
||||||
return hash.Hash160(raw), nil
|
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"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
)
|
)
|
||||||
|
@ -293,9 +294,7 @@ func (s *Stack) ReverseTop(n int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, j := l-n, l-1; i <= j; i, j = i+1, j-1 {
|
slices.Reverse(s.elems[l-n : l])
|
||||||
s.elems[i], s.elems[j] = s.elems[j], s.elems[i]
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1352,10 +1352,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
if t.(stackitem.Immutable).IsReadOnly() {
|
if t.(stackitem.Immutable).IsReadOnly() {
|
||||||
panic(stackitem.ErrReadOnly)
|
panic(stackitem.ErrReadOnly)
|
||||||
}
|
}
|
||||||
a := t.Value().([]stackitem.Item)
|
slices.Reverse(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]
|
|
||||||
}
|
|
||||||
case *stackitem.Buffer:
|
case *stackitem.Buffer:
|
||||||
b := t.Value().([]byte)
|
b := t.Value().([]byte)
|
||||||
slices.Reverse(b)
|
slices.Reverse(b)
|
||||||
|
|
Loading…
Add table
Reference in a new issue