mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
vm: optimise emit.Array() to use NEWARRAY0 for zero-lenght arrays
This commit is contained in:
parent
2f18b114f2
commit
0e1f85b2bf
3 changed files with 6 additions and 8 deletions
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
|
@ -29,7 +28,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
|
@ -89,11 +87,7 @@ func newOracle() *Oracle {
|
|||
defer o.UpdateHash()
|
||||
|
||||
w := io.NewBufBinWriter()
|
||||
emit.Opcodes(w.BinWriter, opcode.NEWARRAY0)
|
||||
emit.Int(w.BinWriter, int64(callflag.All))
|
||||
emit.String(w.BinWriter, "finish")
|
||||
emit.Bytes(w.BinWriter, o.Hash.BytesBE())
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemContractCall)
|
||||
emit.AppCall(w.BinWriter, o.Hash, "finish", callflag.All)
|
||||
o.oracleScript = w.Bytes()
|
||||
|
||||
desc := newDescriptor("request", smartcontract.VoidType,
|
||||
|
|
|
@ -76,6 +76,10 @@ func bigInt(w *io.BinWriter, n *big.Int) {
|
|||
|
||||
// Array emits array of elements to the given buffer.
|
||||
func Array(w *io.BinWriter, es ...interface{}) {
|
||||
if len(es) == 0 {
|
||||
Opcodes(w, opcode.NEWARRAY0)
|
||||
return
|
||||
}
|
||||
for i := len(es) - 1; i >= 0; i-- {
|
||||
switch e := es[i].(type) {
|
||||
case []interface{}:
|
||||
|
|
|
@ -177,7 +177,7 @@ func TestEmitArray(t *testing.T) {
|
|||
buf := io.NewBufBinWriter()
|
||||
Array(buf.BinWriter)
|
||||
require.NoError(t, buf.Err)
|
||||
assert.EqualValues(t, []byte{byte(opcode.PUSH0), byte(opcode.PACK)}, buf.Bytes())
|
||||
assert.EqualValues(t, []byte{byte(opcode.NEWARRAY0)}, buf.Bytes())
|
||||
})
|
||||
|
||||
t.Run("invalid type", func(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue