Skip to content

Commit cf51128

Browse files
committed
refactor: simplify packageHash method
1 parent 431a802 commit cf51128

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

internal/cache/cache.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,29 @@ func (c *Cache) pkgActionID(pkg *packages.Package, mode HashMode) (cache.ActionI
128128
}
129129

130130
func (c *Cache) packageHash(pkg *packages.Package, mode HashMode) (string, error) {
131-
hashResI, ok := c.pkgHashes.Load(pkg)
132-
if ok {
133-
hashRes := hashResI.(hashResults)
134-
if _, ok := hashRes[mode]; !ok {
135-
return "", fmt.Errorf("no mode %d in hash result", mode)
131+
results, found := c.pkgHashes.Load(pkg)
132+
if found {
133+
hashRes := results.(hashResults)
134+
if result, ok := hashRes[mode]; ok {
135+
return result, nil
136136
}
137137

138-
return hashRes[mode], nil
138+
return "", fmt.Errorf("no mode %d in hash result", mode)
139139
}
140140

141141
hashRes, err := c.computePkgHash(pkg)
142142
if err != nil {
143143
return "", err
144144
}
145145

146-
if _, ok := hashRes[mode]; !ok {
146+
result, found := hashRes[mode]
147+
if !found {
147148
return "", fmt.Errorf("invalid mode %d", mode)
148149
}
149150

150151
c.pkgHashes.Store(pkg, hashRes)
151152

152-
return hashRes[mode], nil
153+
return result, nil
153154
}
154155

155156
// computePkgHash computes a package's hash.

0 commit comments

Comments
 (0)