From b062bc1c685048b3392e5f8ded493d5d08df52ef Mon Sep 17 00:00:00 2001 From: thesayyn Date: Wed, 1 Nov 2023 14:10:04 -0700 Subject: [PATCH] dont use slices --- cmd/gomtree/cmd/mutate.go | 22 +++++++++++----------- go.mod | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/gomtree/cmd/mutate.go b/cmd/gomtree/cmd/mutate.go index 1114b5b..7d858ce 100644 --- a/cmd/gomtree/cmd/mutate.go +++ b/cmd/gomtree/cmd/mutate.go @@ -5,7 +5,6 @@ import ( "io" "math" "os" - "slices" "strings" cli "github.com/urfave/cli/v2" @@ -76,20 +75,21 @@ func mutateAction(c *cli.Context) error { &tidyVisitor, } - dropped := []int{} + dropped := map[int]bool{} entries := []mtree.Entry{} skip: for _, entry := range spec.Entries { - - if entry.Parent != nil && slices.Contains(dropped, entry.Parent.Pos) { - if entry.Type == mtree.DotDotType { - // directory for this .. has been dropped so shall this - continue + if entry.Parent != nil { + if _, ok := dropped[entry.Parent.Pos]; ok { + if entry.Type == mtree.DotDotType { + // directory for this .. has been dropped so shall this + continue + } + entry.Parent = entry.Parent.Parent + // TODO: i am not sure if this is the correct behavior + entry.Raw = strings.TrimPrefix(entry.Raw, " ") } - entry.Parent = entry.Parent.Parent - // TODO: i am not sure if this is the correct behavior - entry.Raw = strings.TrimPrefix(entry.Raw, " ") } for _, visitor := range visitors { @@ -99,7 +99,7 @@ skip: } if drop { - dropped = append(dropped, entry.Pos) + dropped[entry.Pos] = true continue skip } } diff --git a/go.mod b/go.mod index 5d44607..944aeaa 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/vbatts/go-mtree -go 1.18 +go 1.17 require ( github.com/davecgh/go-spew v1.1.1