mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-09-20 22:51:55 +00:00
Dont pre-allocate errors slice. (#1083)
This commit is contained in:
parent
1f0fd91205
commit
e47cc2451f
4 changed files with 7 additions and 7 deletions
|
@ -82,7 +82,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk) err
|
|||
}
|
||||
|
||||
var scanned uint64
|
||||
scanErrs := sources.NewScanErrors(len(projects))
|
||||
scanErrs := sources.NewScanErrors()
|
||||
|
||||
for _, proj := range projects {
|
||||
proj := proj
|
||||
|
|
|
@ -12,8 +12,8 @@ type ScanErrors struct {
|
|||
}
|
||||
|
||||
// NewScanErrors creates a new thread safe error collector.
|
||||
func NewScanErrors(projects int) *ScanErrors {
|
||||
return &ScanErrors{errors: make([]error, 0, projects)}
|
||||
func NewScanErrors() *ScanErrors {
|
||||
return &ScanErrors{errors: make([]error, 0)}
|
||||
}
|
||||
|
||||
// Add an error to the collection in a thread-safe manner.
|
||||
|
|
|
@ -37,7 +37,7 @@ func TestNewScanErrors(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := NewScanErrors(tc.projects)
|
||||
got := NewScanErrors()
|
||||
|
||||
if !reflect.DeepEqual(got, tc.want) {
|
||||
t.Errorf("got %+v, want %+v", got, tc.want)
|
||||
|
@ -76,7 +76,7 @@ func TestScanErrorsAdd(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
se := NewScanErrors(tc.wantErr)
|
||||
se := NewScanErrors()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < tc.concurrency; i++ {
|
||||
|
@ -127,7 +127,7 @@ func TestScanErrorsCount(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
se := NewScanErrors(tc.wantErrCnt)
|
||||
se := NewScanErrors()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < tc.concurrency; i++ {
|
||||
|
|
|
@ -338,7 +338,7 @@ func (s *Source) scanRepos(ctx context.Context, chunksChan chan *sources.Chunk)
|
|||
// If there is resume information available, limit this scan to only the repos that still need scanning.
|
||||
reposToScan, progressIndexOffset := sources.FilterReposToResume(s.repos, s.GetProgress().EncodedResumeInfo)
|
||||
s.repos = reposToScan
|
||||
scanErrs := sources.NewScanErrors(len(s.repos))
|
||||
scanErrs := sources.NewScanErrors()
|
||||
|
||||
for i, repo := range s.repos {
|
||||
i, repoURL := i, repo
|
||||
|
|
Loading…
Reference in a new issue