neo-go/pkg/vm/slot.go

65 lines
1.3 KiB
Go
Raw Normal View History

2020-05-07 08:45:24 +00:00
package vm
import (
2021-09-08 14:27:11 +00:00
"encoding/json"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
)
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
// slot is a fixed-size slice of stack items.
type slot []stackitem.Item
2020-05-07 08:45:24 +00:00
// init sets static slot size to n. It is intended to be used only by INITSSLOT.
func (s *slot) init(n int, rc *refCounter) {
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
if *s != nil {
panic("already initialized")
}
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
*s = make([]stackitem.Item, n)
*rc += refCounter(n) // Virtual "Null" elements.
2020-05-08 12:34:32 +00:00
}
2020-05-07 08:45:24 +00:00
// Set sets i-th storage slot.
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
func (s slot) Set(i int, item stackitem.Item, refs *refCounter) {
if s[i] == item {
2020-05-08 12:34:32 +00:00
return
}
refs.Remove(s[i])
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
s[i] = item
refs.Add(item)
2020-05-07 08:45:24 +00:00
}
// Get returns the item contained in the i-th slot.
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
func (s slot) Get(i int) stackitem.Item {
if item := s[i]; item != nil {
2020-05-07 08:45:24 +00:00
return item
}
return stackitem.Null{}
2020-05-07 08:45:24 +00:00
}
// ClearRefs removes all slot variables from the reference counter.
func (s slot) ClearRefs(refs *refCounter) {
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
for _, item := range s {
refs.Remove(item)
}
}
// Size returns the slot size.
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
func (s slot) Size() int {
if s == nil {
panic("not initialized")
}
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
return len(s)
}
2021-09-08 14:27:11 +00:00
// MarshalJSON implements the JSON marshalling interface.
vm: simplify slot and make it private Hiding refcounter inside a slot is actually a good idea, but it makes the structure somewhat bigger, especially given that the refcounter is the same and belongs more to VM or Context. New structure is a bit more efficient: name old time/op new time/op delta ScriptFibonacci-8 672µs ± 2% 644µs ± 0% -4.15% (p=0.008 n=5+5) ScriptNestedRefCount-8 1.08ms ± 1% 1.05ms ± 2% -2.56% (p=0.008 n=5+5) ScriptPushPop/4-8 1.52µs ± 1% 1.47µs ± 1% -3.14% (p=0.008 n=5+5) ScriptPushPop/16-8 3.66µs ± 1% 3.54µs ± 1% -3.24% (p=0.008 n=5+5) ScriptPushPop/128-8 24.7µs ± 1% 23.2µs ± 1% -6.14% (p=0.008 n=5+5) ScriptPushPop/1024-8 183µs ± 1% 173µs ± 1% -5.01% (p=0.008 n=5+5) name old alloc/op new alloc/op delta ScriptFibonacci-8 114kB ± 0% 114kB ± 0% ~ (p=0.079 n=4+5) ScriptNestedRefCount-8 241kB ± 0% 241kB ± 0% ~ (p=0.333 n=5+4) ScriptPushPop/4-8 160B ± 0% 160B ± 0% ~ (all equal) ScriptPushPop/16-8 640B ± 0% 640B ± 0% ~ (all equal) ScriptPushPop/128-8 8.70kB ± 0% 8.70kB ± 0% ~ (all equal) ScriptPushPop/1024-8 73.2kB ± 0% 73.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta ScriptFibonacci-8 3.17k ± 0% 3.17k ± 0% -0.03% (p=0.008 n=5+5) ScriptNestedRefCount-8 10.7k ± 0% 10.7k ± 0% ~ (all equal) ScriptPushPop/4-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) ScriptPushPop/16-8 32.0 ± 0% 32.0 ± 0% ~ (all equal) ScriptPushPop/128-8 259 ± 0% 259 ± 0% ~ (all equal) ScriptPushPop/1024-8 2.05k ± 0% 2.05k ± 0% ~ (all equal) It'd be especially nice to internalize static slot, but as we can't compare slices it's not possible.
2021-11-30 12:03:01 +00:00
func (s slot) MarshalJSON() ([]byte, error) {
arr := make([]json.RawMessage, len(s))
for i := range s {
data, err := stackitem.ToJSONWithTypes(s[i])
2021-09-08 14:27:11 +00:00
if err == nil {
arr[i] = data
}
}
return json.Marshal(arr)
}