From 879831d31add4b4c334c1a2edcce4171615dc96b Mon Sep 17 00:00:00 2001 From: Lorenz Bauer Date: Wed, 20 Mar 2024 12:50:17 +0000 Subject: [PATCH] btf: rename walkType to children children is a much better name than walkType, so let's use that. Signed-off-by: Lorenz Bauer --- btf/traversal.go | 14 ++++++++------ btf/traversal_test.go | 2 +- btf/types_test.go | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/btf/traversal.go b/btf/traversal.go index 5a7387b06..a43fec024 100644 --- a/btf/traversal.go +++ b/btf/traversal.go @@ -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 } @@ -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. @@ -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. diff --git a/btf/traversal_test.go b/btf/traversal_test.go index 2b87ccacc..879b0bf25 100644 --- a/btf/traversal_test.go +++ b/btf/traversal_test.go @@ -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)) }) }) diff --git a/btf/types_test.go b/btf/types_test.go index df2569805..642f06704 100644 --- a/btf/types_test.go +++ b/btf/types_test.go @@ -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 { @@ -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) @@ -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) } }) }