diff --git a/go/types/goodarch.go b/go/types/goodarch.go deleted file mode 100644 index 94824f9..0000000 --- a/go/types/goodarch.go +++ /dev/null @@ -1,57 +0,0 @@ -package types - -import ( - "runtime" - "strings" -) - -// Code for determining system-specific files stolen from -// goinstall. We can't automatically generate goosList and -// goarchList if this package is to remain goinstallable. - -const goosList = "darwin freebsd linux plan9 windows " -const goarchList = "386 amd64 arm " - -// goodOSArch returns false if the filename contains a $GOOS or $GOARCH -// suffix which does not match the current system. -// The recognized filename formats are: -// -// name_$(GOOS).* -// name_$(GOARCH).* -// name_$(GOOS)_$(GOARCH).* -// -func goodOSArch(filename string) (ok bool) { - if dot := strings.Index(filename, "."); dot != -1 { - filename = filename[:dot] - } - l := strings.Split(filename, "_") - n := len(l) - if n == 0 { - return true - } - if good, known := goodOS[l[n-1]]; known { - return good - } - if good, known := goodArch[l[n-1]]; known { - if !good || n < 2 { - return false - } - good, known = goodOS[l[n-2]] - return good || !known - } - return true -} - -var goodOS = make(map[string]bool) -var goodArch = make(map[string]bool) - -func init() { - goodOS = make(map[string]bool) - goodArch = make(map[string]bool) - for _, v := range strings.Fields(goosList) { - goodOS[v] = v == runtime.GOOS - } - for _, v := range strings.Fields(goarchList) { - goodArch[v] = v == runtime.GOARCH - } -} diff --git a/go/types/types.go b/go/types/types.go index dc11adf..68c61bf 100644 --- a/go/types/types.go +++ b/go/types/types.go @@ -12,7 +12,6 @@ import ( "path/filepath" "runtime" "strconv" - "strings" "github.com/rogpeppe/godef/go/ast" "github.com/rogpeppe/godef/go/parser" @@ -82,7 +81,16 @@ func DefaultImporter(path string, srcDir string) *ast.Package { if err != nil { return nil } - pkgs, err := parser.ParseDir(FileSet, bpkg.Dir, isGoFile, 0, DefaultImportPathToName) + // Create a map for fast lookup of the files we want to parse + parseFiles := make(map[string]struct{}, len(bpkg.GoFiles)) + for _, name := range bpkg.GoFiles { + parseFiles[name] = struct{}{} + } + filter := func(d os.FileInfo) bool { + _, found := parseFiles[d.Name()] + return found + } + pkgs, err := parser.ParseDir(FileSet, bpkg.Dir, filter, 0, DefaultImportPathToName) if err != nil { if Debug { switch err := err.(type) { @@ -112,18 +120,6 @@ func DefaultImportPathToName(path, srcDir string) (string, error) { return pkg.Name, err } -// isGoFile returns true if we will consider the file as a -// possible candidate for parsing as part of a package. -// Including _test.go here isn't quite right, but what -// else can we do? -// -func isGoFile(d os.FileInfo) bool { - return strings.HasSuffix(d.Name(), ".go") && - !strings.HasSuffix(d.Name(), "_test.go") && - !strings.HasPrefix(d.Name(), ".") && - goodOSArch(d.Name()) -} - // When Debug is true, log messages will be printed. var Debug = false