Skip to content

Commit

Permalink
improve caching (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzh8829 committed Aug 18, 2023
1 parent f2bdf7e commit c7e6d5d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type block struct {
var vscDirs = []string{".git", ".hg", ".bzr", ".svn"}

type cacheEntry struct {
file string
err error
dir string
err error
}

var pkgCache = map[string]cacheEntry{}
Expand All @@ -46,16 +46,16 @@ func findFile(filePath string) (string, error) {
dir, file := filepath.Split(filePath)
var result cacheEntry
var ok bool
if result, ok = pkgCache[filePath]; !ok {
if result, ok = pkgCache[dir]; !ok {
pkg, err := build.Import(dir, ".", build.FindOnly)
if err == nil {
result = cacheEntry{filepath.Join(pkg.Dir, file), nil}
result = cacheEntry{filepath.Join(pkg.Dir), nil}

Check failure on line 52 in main.go

View workflow job for this annotation

GitHub Actions / lint

badCall: suspicious Join on 1 argument (gocritic)
} else {
result = cacheEntry{"", err}
}
pkgCache[filePath] = result
pkgCache[dir] = result
}
return result.file, result.err
return filepath.Join(result.dir, file), result.err
}

// findRepositoryRoot finds the VCS root dir of a given dir
Expand Down

0 comments on commit c7e6d5d

Please sign in to comment.