diff options
| author | 2025-11-17 00:00:00 +0000 | |
|---|---|---|
| committer | 2025-11-17 00:00:00 +0000 | |
| commit | 4789df803aba25340ebe0eaf472ad22bd92d7f96 (patch) | |
| tree | 10e7e76f5f87e1c0d35d2793206ea4d0e8b63423 /pack_pack.go | |
| parent | Revert "Compute checksum when reading packfiles" (diff) | |
| signature | ||
pack: Use a Go map with a mutex instead of a sync.Map for packfiles
Very few writes, you don't typically see more than a dozen packfiles.
A ton of reads. Go maps are the obvious choice.
Diffstat (limited to 'pack_pack.go')
| -rw-r--r-- | pack_pack.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pack_pack.go b/pack_pack.go index 5c2c8628..d7b565f5 100644 --- a/pack_pack.go +++ b/pack_pack.go @@ -570,3 +570,27 @@ func (pf *packFile) cursor(ofs uint64) (io.Reader, error) { } return bytes.NewReader(pf.data[ofs:]), nil } + +func (repo *Repository) packFile(rel string) (*packFile, error) { + repo.packFilesMu.RLock() + pf, ok := repo.packFiles[rel] + repo.packFilesMu.RUnlock() + if ok { + return pf, nil + } + + pf, err := openPackFile(repo.repoPath(rel), rel) + if err != nil { + return nil, err + } + + repo.packFilesMu.Lock() + if existing, ok := repo.packFiles[rel]; ok { + repo.packFilesMu.Unlock() + _ = pf.Close() + return existing, nil + } + repo.packFiles[rel] = pf + repo.packFilesMu.Unlock() + return pf, nil +} |
