internal/fetch: only need to count non-test files

Remove the map of non-test files and just count them; that's all we
need.

Change-Id: I593323b3b2a07d66bd9e47c5c04e3c5720bd04f4
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/257662
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Trust: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/fetch/load.go b/internal/fetch/load.go
index 25f31c8..b2d8aac 100644
--- a/internal/fetch/load.go
+++ b/internal/fetch/load.go
@@ -162,7 +162,7 @@
 	var (
 		fset            = token.NewFileSet()
 		goFiles         = make(map[string]*ast.File)
-		nonTestFiles    = make(map[string]*ast.File)
+		numNonTestFiles int
 		packageName     string
 		packageNameFile string // Name of file where packageName came from.
 	)
@@ -179,11 +179,11 @@
 		if strings.HasSuffix(name, "_test.go") {
 			continue
 		}
-		// Keep track of non-test files to get the package name, and also
-		// because a directory with only test files doesn't count as a Go
-		// package.
-		nonTestFiles[name] = pf
-		if len(nonTestFiles) == 1 {
+		// Keep track of the number of non-test files to check that the package name is the same.
+		// and also because a directory with only test files doesn't count as a
+		// Go package.
+		numNonTestFiles++
+		if numNonTestFiles == 1 {
 			packageName = pf.Name.Name
 			packageNameFile = name
 		} else if pf.Name.Name != packageName {
@@ -194,7 +194,7 @@
 			}}
 		}
 	}
-	if len(nonTestFiles) == 0 {
+	if numNonTestFiles == 0 {
 		// This directory doesn't contain a package, or at least not one
 		// that matches this build context.
 		return "", nil, nil, derrors.NotFound