mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-16 21:16:30 +00:00
transaction: microoptimize multiattribute check
We can't have more than 256 attribute types, so allocate and use 32 bytes instead of a whole map. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
f15a163cdf
commit
e8a86e617b
1 changed files with 4 additions and 3 deletions
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/bitfield"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
|
@ -428,14 +429,14 @@ func (t *Transaction) isValid() error {
|
|||
}
|
||||
}
|
||||
}
|
||||
attrs := map[AttrType]bool{}
|
||||
var attrBits = bitfield.New(256)
|
||||
for i := range t.Attributes {
|
||||
typ := t.Attributes[i].Type
|
||||
if !typ.allowMultiple() {
|
||||
if attrs[typ] {
|
||||
if attrBits.IsSet(int(typ)) {
|
||||
return fmt.Errorf("%w: multiple '%s' attributes", ErrInvalidAttribute, typ.String())
|
||||
}
|
||||
attrs[typ] = true
|
||||
attrBits.Set(int(typ))
|
||||
}
|
||||
}
|
||||
if len(t.Script) == 0 {
|
||||
|
|
Loading…
Add table
Reference in a new issue