Skip to content

Commit

Permalink
btf: rename walkType to children
Browse files Browse the repository at this point in the history
children is a much better name than walkType, so let's use that.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
  • Loading branch information
lmb committed Mar 27, 2024
1 parent 6dd3145 commit 879831d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions btf/traversal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func postorderTraversal(root Type, skip func(Type) (skip bool)) postorderIterato
}

po := postorderIterator{root: root, skip: skip}
walkType(root, po.push)
children(root, po.push)

return po
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func (po *postorderIterator) Next() bool {
po.walked.Push(true)

// Add all direct children to todo.
walkType(*t, po.push)
children(*t, po.push)
} else {
// We've walked this type previously, so we now know that all
// children have been handled.
Expand Down Expand Up @@ -114,18 +114,20 @@ func modifyGraphPreorder(root Type, fn func(node Type) (replacement Type, cont b
*node = sub

if cont {
walkType(*node, walk)
children(*node, walk)
}
}

if cont {
walkType(sub, walk)
children(sub, walk)
}
return sub
}

// walkType calls fn on each child of typ.
func walkType(typ Type, fn func(*Type)) {
// children calls fn on each child of typ.
//
// Iteration stops early if fn returns false.
func children(typ Type, fn func(child *Type)) {
// Explicitly type switch on the most common types to allow the inliner to
// do its work. This avoids allocating intermediate slices from walk() on
// the heap.
Expand Down
2 changes: 1 addition & 1 deletion btf/traversal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestPostorderTraversalVmlinux(t *testing.T) {
t.Fatalf("Expected %s got %s as last type", typ, last)
}

walkType(typ, func(child *Type) {
children(typ, func(child *Type) {
qt.Check(t, qt.IsTrue(seen[*child]), qt.Commentf("missing child %s", *child))
})
})
Expand Down
6 changes: 3 additions & 3 deletions btf/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestType(t *testing.T) {
}

var a []*Type
walkType(typ, func(t *Type) { a = append(a, t) })
children(typ, func(t *Type) { a = append(a, t) })

if _, ok := typ.(*cycle); !ok {
if n := countChildren(t, reflect.TypeOf(typ)); len(a) < n {
Expand All @@ -225,7 +225,7 @@ func TestType(t *testing.T) {
}

var b []*Type
walkType(typ, func(t *Type) { b = append(b, t) })
children(typ, func(t *Type) { b = append(b, t) })

if diff := cmp.Diff(a, b, compareTypes); diff != "" {
t.Errorf("Walk mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -491,7 +491,7 @@ func BenchmarkWalk(b *testing.B) {

for i := 0; i < b.N; i++ {
var dq typeDeque
walkType(typ, dq.Push)
children(typ, dq.Push)
}
})
}
Expand Down

0 comments on commit 879831d

Please sign in to comment.