From 6043b12efb96192ff68c5aaeba40c4485a948f94 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Wed, 12 Aug 2020 10:17:55 +0200 Subject: [PATCH] cleaner recurseParents() implementation --- internal/resolver/resolver.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index 409ea0a099e..e4249a100dd 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -228,16 +228,12 @@ func (r *resolver) resolveWithoutSymlinks(sourceDir string, importPath string) ( // recurseParents recursively walks up the dirInfo hierarchy (child -> parent) // the walker func returns true to stop (i.e: match found) and false to continue -func (r *resolver) recurseParents(current *dirInfo, walker func(*dirInfo) bool) bool { - cursor := current - - for cursor != nil { - if matched := walker(cursor); matched { +func (r *resolver) recurseParents(dirInfo *dirInfo, walker func(*dirInfo) bool) bool { + for info := dirInfo; info != nil; info = info.parent { + if matched := walker(info); matched { return true } - cursor = cursor.parent } - return false }