forked from quay/claircore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpool.go
More file actions
48 lines (41 loc) · 1.14 KB
/
Copy pathpool.go
File metadata and controls
48 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package jsonblob
import (
"sync"
"github.com/quay/claircore"
"github.com/quay/claircore/libvuln/driver"
)
var (
vulnerability sync.Pool
enrichment sync.Pool
)
func getVulnerability() *claircore.Vulnerability {
if v := vulnerability.Get(); v != nil {
return v.(*claircore.Vulnerability)
}
return new(claircore.Vulnerability)
}
// ReturnVulnerability can be used by callers to return
// [claircore.Vulnerability] objects from [Loader.All] iterators to a common
// pool.
//
// This may take some pressure off the garbage collector.
func ReturnVulnerability(v *claircore.Vulnerability) {
// Reset the fields.
*v = claircore.Vulnerability{}
vulnerability.Put(v)
}
func getEnrichment() *driver.EnrichmentRecord {
if v := enrichment.Get(); v != nil {
return v.(*driver.EnrichmentRecord)
}
return new(driver.EnrichmentRecord)
}
// ReturnEnrichment can be used by callers to return [driver.EnrichmentRecord]
// objects from [Loader.All] iterators to a common pool.
//
// This may take some pressure off the garbage collector.
func ReturnEnrichment(e *driver.EnrichmentRecord) {
// Reset the fields.
*e = driver.EnrichmentRecord{}
enrichment.Put(e)
}