Skip to content

Commit 4f862b6

Browse files
sped up a function
1 parent 963a05a commit 4f862b6

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

build/build.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -760,23 +760,22 @@ type ParsedPackage struct {
760760
// The given skip paths will not be returned in the results.
761761
// This will not return any `*_test` packages in the results.
762762
func (p *ParsedPackage) Imports(skip ...string) []string {
763-
importMap := make(map[string]struct{})
763+
seen := make(map[string]struct{})
764+
for _, s := range skip {
765+
seen[s] = struct{}{}
766+
}
767+
imports := []string{}
764768
for _, file := range p.GoFiles {
765769
for _, imp := range file.Imports {
766770
path := strings.Trim(imp.Path.Value, `"`)
767-
if !strings.HasSuffix(path, "_test") {
768-
importMap[path] = struct{}{}
771+
if _, ok := seen[path]; !ok {
772+
if !strings.HasSuffix(path, "_test") {
773+
imports = append(imports, path)
774+
}
775+
seen[path] = struct{}{}
769776
}
770777
}
771778
}
772-
for _, skip := range skip {
773-
delete(importMap, skip)
774-
}
775-
776-
imports := make([]string, 0, len(importMap))
777-
for imp := range importMap {
778-
imports = append(imports, imp)
779-
}
780779
sort.Strings(imports)
781780
return imports
782781
}

0 commit comments

Comments
 (0)