Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve caching #16

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,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 @@ -47,16 +47,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}
} 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
Loading