From a113ba3838a191c8d2aeb531731af5cb31aa6e26 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 25 Apr 2020 07:40:50 +0200 Subject: prog: dedup code in ForeachType --- prog/types.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/prog/types.go b/prog/types.go index f07de2b16..4fd602c87 100644 --- a/prog/types.go +++ b/prog/types.go @@ -634,8 +634,17 @@ type ConstValue struct { } func ForeachType(meta *Syscall, f func(Type)) { - seen := make(map[*StructDesc]bool) var rec func(t Type) + seen := make(map[*StructDesc]bool) + recStruct := func(desc *StructDesc) { + if seen[desc] { + return // prune recursion via pointers to structs/unions + } + seen[desc] = true + for _, f := range desc.Fields { + rec(f) + } + } rec = func(t Type) { f(t) switch a := t.(type) { @@ -644,21 +653,9 @@ func ForeachType(meta *Syscall, f func(Type)) { case *ArrayType: rec(a.Type) case *StructType: - if seen[a.StructDesc] { - return // prune recursion via pointers to structs/unions - } - seen[a.StructDesc] = true - for _, f := range a.Fields { - rec(f) - } + recStruct(a.StructDesc) case *UnionType: - if seen[a.StructDesc] { - return // prune recursion via pointers to structs/unions - } - seen[a.StructDesc] = true - for _, opt := range a.Fields { - rec(opt) - } + recStruct(a.StructDesc) case *ResourceType, *BufferType, *VmaType, *LenType, *FlagsType, *ConstType, *IntType, *ProcType, *CsumType: default: -- cgit mrf-deployment