diff --git a/internal/licenses/licenses.go b/internal/licenses/licenses.go index aecbba730..e22e903c3 100644 --- a/internal/licenses/licenses.go +++ b/internal/licenses/licenses.go @@ -26,8 +26,10 @@ import ( "fmt" "io" "io/fs" + "maps" "path" "path/filepath" + "slices" "sort" "strings" "sync" @@ -575,7 +577,7 @@ func DetectFile(contents []byte, filename string, logf func(string, ...any)) ([] logf("%s failed to classify license (%+v), skipping", filename, cov) return []string{unknownLicenseType}, cov } - return setToSortedSlice(types), cov + return slices.Sorted(maps.Keys(types)), cov } // Redistributable reports whether the set of license types establishes that a @@ -603,12 +605,3 @@ func types(lics []*License) []string { } return types } - -func setToSortedSlice(m map[string]bool) []string { - var s []string - for e := range m { - s = append(s, e) - } - sort.Strings(s) - return s -} diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go index a91825079..1db5e72fe 100644 --- a/internal/postgres/insert_module.go +++ b/internal/postgres/insert_module.go @@ -12,6 +12,8 @@ import ( "fmt" "hash/fnv" "io" + "maps" + "slices" "sort" "strings" "unicode/utf8" @@ -442,15 +444,7 @@ func insertPaths(ctx context.Context, tx *database.DB, m *internal.Module) (path curPathsSet[internal.V1Path(u.Path, m.ModulePath)] = true curPathsSet[internal.SeriesPathForModule(m.ModulePath)] = true } - return upsertPaths(ctx, tx, stringSetToSlice(curPathsSet)) -} - -func stringSetToSlice(m map[string]bool) []string { - var s []string - for e := range m { - s = append(s, e) - } - return s + return upsertPaths(ctx, tx, slices.Collect(maps.Keys(curPathsSet))) } func insertUnits(ctx context.Context, db *database.DB, unitValues []any) (pathIDToUnitID map[int]int, err error) { @@ -581,7 +575,7 @@ func insertImports(ctx context.Context, tx *database.DB, importPathSet[imp] = true } } - pathToID, err := upsertPaths(ctx, tx, stringSetToSlice(importPathSet)) + pathToID, err := upsertPaths(ctx, tx, slices.Collect(maps.Keys(importPathSet))) if err != nil { return err }