Skip to content

Commit

Permalink
Simplify code and use map[string]struct{} to replace map[string]bool
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan-ce-lot committed Oct 25, 2022
1 parent f82846e commit c936812
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func main() {
// validate arguments
if len(flag.Args()) > 0 {
var mounts []Mount
vis := make(map[string]bool)
vis := map[string]struct{}{}

for _, v := range flag.Args() {
var fm []Mount
Expand All @@ -254,15 +254,12 @@ func main() {
os.Exit(1)
}
// de-duplicate
var tmp []Mount
for _, v := range fm {
if _, ok := vis[v.Device]; !ok {
tmp = append(tmp, v)
vis[v.Device] = true
mounts = append(mounts, v)
vis[v.Device] = struct{}{}
}
}

mounts = append(mounts, tmp...)
}

m = mounts
Expand Down

0 comments on commit c936812

Please sign in to comment.