[#356] netmap: Simplify zero subnet processing in IterateSubnets

For now we don't need to distinguish cases of missing zero subnet's
attribute and the one with `True` value.

Remove local enum `zeroStatus` of `IterateSubnets` since we need to
distinguish between two statuses and use `bool` variable for this.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-11-22 15:05:21 +03:00 committed by LeL
parent 896cee4bb0
commit abc494b2bc

View file

@ -128,24 +128,12 @@ var errNoSubnets = errors.New("no subnets")
func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error { func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error {
attrs := node.GetAttributes() attrs := node.GetAttributes()
type zeroStatus uint8
const (
_ zeroStatus = iota
// missing attribute of zero subnet
zeroNoAttr
// with `False` attribute
zeroExit
// with `True` attribute
zeroEntry
)
var ( var (
err error err error
id refs.SubnetID id refs.SubnetID
entries uint entries uint
stZero = zeroNoAttr zeroEntry = true
) )
for i := 0; i < len(attrs); i++ { // range must not be used because of attrs mutation in body for i := 0; i < len(attrs); i++ { // range must not be used because of attrs mutation in body
@ -172,15 +160,8 @@ func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error {
// update status of zero subnet // update status of zero subnet
isZero := refs.IsZeroSubnet(&id) isZero := refs.IsZeroSubnet(&id)
if stZero == zeroNoAttr { // in order to not reset if has been already set
if isZero { if isZero {
if val == attrSubnetValEntry { zeroEntry = val == attrSubnetValEntry
// clear True attribute for zero subnet is also possible
stZero = zeroEntry
} else {
stZero = zeroExit
}
}
} }
// continue to process only the subnets to which the node belongs // continue to process only the subnets to which the node belongs
@ -213,7 +194,7 @@ func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error {
entries++ entries++
} }
if stZero == zeroNoAttr { if zeroEntry {
// missing attribute of zero subnet equivalent to entry // missing attribute of zero subnet equivalent to entry
refs.MakeZeroSubnet(&id) refs.MakeZeroSubnet(&id)