setUniqueName is the implementation of [SetUniqueName] that takes whether to add the unique id to the name even if it is already set.
(n Node, addIfSet bool)
| 155 | // setUniqueName is the implementation of [SetUniqueName] that takes whether |
| 156 | // to add the unique id to the name even if it is already set. |
| 157 | func setUniqueName(n Node, addIfSet bool) { |
| 158 | nb := n.AsTree() |
| 159 | pn := nb.Parent |
| 160 | if pn == nil { |
| 161 | return |
| 162 | } |
| 163 | c := atomic.AddUint64(&pn.AsTree().numLifetimeChildren, 1) |
| 164 | id := "-" + strconv.FormatUint(c-1, 10) // must subtract 1 so we start at 0 |
| 165 | if nb.Name == "" { |
| 166 | nb.SetName(nb.NodeType().IDName + id) |
| 167 | } else if addIfSet { |
| 168 | nb.SetName(nb.Name + id) |
| 169 | } |
| 170 | } |
no test coverage detected