@@ -61,9 +61,10 @@ type singleSourceCache interface {
61
61
}
62
62
63
63
type singleSourceCacheMemory struct {
64
- mut sync.RWMutex // protects all maps
64
+ mut sync.RWMutex // protects all fields
65
65
infos map [ProjectAnalyzerInfo ]map [Revision ]projectInfo
66
66
ptrees map [Revision ]pkgtree.PackageTree
67
+ vList []PairedVersion // replaced, never modified
67
68
vMap map [UnpairedVersion ]Revision
68
69
rMap map [Revision ][]UnpairedVersion
69
70
}
@@ -136,13 +137,14 @@ func (c *singleSourceCacheMemory) getPackageTree(r Revision) (pkgtree.PackageTre
136
137
137
138
func (c * singleSourceCacheMemory ) setVersionMap (versionList []PairedVersion ) {
138
139
c .mut .Lock ()
140
+ c .vList = versionList
139
141
// TODO(sdboyer) how do we handle cache consistency here - revs that may
140
142
// be out of date vis-a-vis the ptrees or infos maps?
141
143
for r := range c .rMap {
142
144
c .rMap [r ] = nil
143
145
}
144
146
145
- c .vMap = make (map [UnpairedVersion ]Revision )
147
+ c .vMap = make (map [UnpairedVersion ]Revision , len ( versionList ) )
146
148
147
149
for _ , pv := range versionList {
148
150
u , r := pv .Unpair (), pv .Revision ()
@@ -168,14 +170,16 @@ func (c *singleSourceCacheMemory) getVersionsFor(r Revision) ([]UnpairedVersion,
168
170
}
169
171
170
172
func (c * singleSourceCacheMemory ) getAllVersions () []PairedVersion {
171
- if len (c .vMap ) == 0 {
173
+ c .mut .Lock ()
174
+ vList := c .vList
175
+ c .mut .Unlock ()
176
+
177
+ if vList == nil {
172
178
return nil
173
179
}
174
- vlist := make ([]PairedVersion , 0 , len (c .vMap ))
175
- for v , r := range c .vMap {
176
- vlist = append (vlist , v .Pair (r ))
177
- }
178
- return vlist
180
+ cp := make ([]PairedVersion , len (vList ))
181
+ copy (cp , vList )
182
+ return cp
179
183
}
180
184
181
185
func (c * singleSourceCacheMemory ) getRevisionFor (uv UnpairedVersion ) (Revision , bool ) {
0 commit comments