@@ -23,7 +23,7 @@ type PhpPackagesKey struct {
23
23
// process to be reported to the backend.
24
24
type PhpPackages struct {
25
25
numSeen int
26
- data [] PhpPackagesKey
26
+ data map [ PhpPackagesKey ] struct {}
27
27
filteredPkgs []PhpPackagesKey
28
28
}
29
29
@@ -38,7 +38,7 @@ func (packages *PhpPackages) NumSaved() float64 {
38
38
func NewPhpPackages () * PhpPackages {
39
39
p := & PhpPackages {
40
40
numSeen : 0 ,
41
- data : nil ,
41
+ data : make ( map [ PhpPackagesKey ] struct {}) ,
42
42
filteredPkgs : nil ,
43
43
}
44
44
@@ -62,11 +62,11 @@ func NewPhpPackages() *PhpPackages {
62
62
// key does not exist, add it to the map and the slice of filteredPkgs to be
63
63
// sent in the current harvest.
64
64
func (packages * PhpPackages ) Filter (pkgHistory map [PhpPackagesKey ]struct {}) {
65
- if packages == nil || packages .data == nil {
65
+ if packages == nil || len ( packages .data ) == 0 {
66
66
return
67
67
}
68
68
69
- for _ , pkgKey := range packages .data {
69
+ for pkgKey := range packages .data {
70
70
_ , ok := pkgHistory [pkgKey ]
71
71
if ! ok {
72
72
pkgHistory [pkgKey ] = struct {}{}
@@ -107,7 +107,11 @@ func (packages *PhpPackages) AddPhpPackagesFromData(data []byte) error {
107
107
return fmt .Errorf ("unable to parse package version" )
108
108
}
109
109
110
- packages .data = append (packages .data , PhpPackagesKey {name , version })
110
+ pkgKey := PhpPackagesKey {name , version }
111
+ _ , ok = packages .data [pkgKey ]
112
+ if ! ok {
113
+ packages .data [pkgKey ] = struct {}{}
114
+ }
111
115
}
112
116
113
117
packages .numSeen = 1
@@ -158,7 +162,7 @@ func (packages *PhpPackages) FailedHarvest(newHarvest *Harvest) {
158
162
159
163
// Empty returns true if the collection is empty.
160
164
func (packages * PhpPackages ) Empty () bool {
161
- return nil == packages || nil == packages . data || 0 == packages .numSeen
165
+ return nil == packages || len ( packages . data ) == 0 || 0 == packages .numSeen
162
166
}
163
167
164
168
// Data marshals the collection to JSON according to the schema expected
0 commit comments