collectChildren returns indices of direct children of node i. The returned slice is reused across calls; callers must not retain it.
(i int)
| 118 | // collectChildren returns indices of direct children of node i. |
| 119 | // The returned slice is reused across calls; callers must not retain it. |
| 120 | func (d *astDecoder) collectChildren(i int) []int { |
| 121 | d.childBuf = d.childBuf[:0] |
| 122 | if i+1 >= d.nodeCount { |
| 123 | return d.childBuf |
| 124 | } |
| 125 | firstChild := i + 1 |
| 126 | if d.nodeField(firstChild, NodeOffsetParent) != uint32(i) { |
| 127 | return d.childBuf |
| 128 | } |
| 129 | d.childBuf = append(d.childBuf, firstChild) |
| 130 | next := int(d.nodeField(firstChild, NodeOffsetNext)) |
| 131 | for next != 0 { |
| 132 | d.childBuf = append(d.childBuf, next) |
| 133 | next = int(d.nodeField(next, NodeOffsetNext)) |
| 134 | } |
| 135 | return d.childBuf |
| 136 | } |
| 137 | |
| 138 | func (d *astDecoder) decode() (*ast.Node, error) { |
| 139 | if d.nodeCount < 2 { |