From abc494b2bc3768d41296ea30722a6a8334547c82 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 22 Nov 2021 15:05:21 +0300 Subject: [PATCH] [#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 --- netmap/attributes.go | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/netmap/attributes.go b/netmap/attributes.go index 47dbc5c..da9f28c 100644 --- a/netmap/attributes.go +++ b/netmap/attributes.go @@ -128,24 +128,12 @@ var errNoSubnets = errors.New("no subnets") func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error { attrs := node.GetAttributes() - type zeroStatus uint8 - - const ( - _ zeroStatus = iota - // missing attribute of zero subnet - zeroNoAttr - // with `False` attribute - zeroExit - // with `True` attribute - zeroEntry - ) - var ( err error id refs.SubnetID entries uint - stZero = zeroNoAttr + zeroEntry = true ) 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 isZero := refs.IsZeroSubnet(&id) - if stZero == zeroNoAttr { // in order to not reset if has been already set - if isZero { - if val == attrSubnetValEntry { - // clear True attribute for zero subnet is also possible - stZero = zeroEntry - } else { - stZero = zeroExit - } - } + if isZero { + zeroEntry = val == attrSubnetValEntry } // 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++ } - if stZero == zeroNoAttr { + if zeroEntry { // missing attribute of zero subnet equivalent to entry refs.MakeZeroSubnet(&id)