From a9d31ec7b911a4247cba6b9acc645b11171bbb07 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Sun, 3 Sep 2023 23:23:25 +0100 Subject: [PATCH] Avoid unnecessary type assertion in mfs driver We already make sure the node in *dir Signed-off-by: Milos Gajdos --- registry/storage/driver/inmemory/mfs.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/registry/storage/driver/inmemory/mfs.go b/registry/storage/driver/inmemory/mfs.go index 7eaa3c57..f3837c5f 100644 --- a/registry/storage/driver/inmemory/mfs.go +++ b/registry/storage/driver/inmemory/mfs.go @@ -1,7 +1,6 @@ package inmemory import ( - "errors" "fmt" "io" "path" @@ -98,13 +97,12 @@ func (d *dir) list(p string) ([]string, error) { return nil, errIsNotDir } - dir, ok := n.(*dir) - if !ok { - return nil, errors.New("not a directory") - } + // NOTE(milosgajdos): this is safe to do because + // n can only be *dir due to the compile time check + dirChildren := n.(*dir).children - children := make([]string, 0, len(dir.children)) - for _, child := range dir.children { + children := make([]string, 0, len(dirChildren)) + for _, child := range dirChildren { children = append(children, child.path()) }