Skip to content

Commit c7e6d5d

Browse files
authored
improve caching (jandelgado#16)
1 parent f2bdf7e commit c7e6d5d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type block struct {
3434
var vscDirs = []string{".git", ".hg", ".bzr", ".svn"}
3535

3636
type cacheEntry struct {
37-
file string
38-
err error
37+
dir string
38+
err error
3939
}
4040

4141
var pkgCache = map[string]cacheEntry{}
@@ -46,16 +46,16 @@ func findFile(filePath string) (string, error) {
4646
dir, file := filepath.Split(filePath)
4747
var result cacheEntry
4848
var ok bool
49-
if result, ok = pkgCache[filePath]; !ok {
49+
if result, ok = pkgCache[dir]; !ok {
5050
pkg, err := build.Import(dir, ".", build.FindOnly)
5151
if err == nil {
52-
result = cacheEntry{filepath.Join(pkg.Dir, file), nil}
52+
result = cacheEntry{filepath.Join(pkg.Dir), nil}
5353
} else {
5454
result = cacheEntry{"", err}
5555
}
56-
pkgCache[filePath] = result
56+
pkgCache[dir] = result
5757
}
58-
return result.file, result.err
58+
return filepath.Join(result.dir, file), result.err
5959
}
6060

6161
// findRepositoryRoot finds the VCS root dir of a given dir

0 commit comments

Comments
 (0)