Dont pre-allocate errors slice. (#1083)

This commit is contained in:
ahrav 2023-02-08 17:33:30 -08:00 committed by GitHub
parent 1f0fd91205
commit e47cc2451f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View file

@ -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

View file

@ -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.

View file

@ -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++ {

View file

@ -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