Skip to content

Fix initialization of boots slice in ParseBootstraps#8257

Open
fcchbjm wants to merge 3 commits intoAdguardTeam:masterfrom
fcchbjm:master
Open

Fix initialization of boots slice in ParseBootstraps#8257
fcchbjm wants to merge 3 commits intoAdguardTeam:masterfrom
fcchbjm:master

Conversation

@fcchbjm
Copy link

@fcchbjm fcchbjm commented Feb 21, 2026

Small Performance Optimization
Reduce the time complexity from O(n²) to O(1)

Copy link

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 To request another review, post a new comment with "/windsurf-review".

opts *upstream.Options,
) (boots []*upstream.UpstreamResolver, err error) {
boots = make([]*upstream.UpstreamResolver, 0, len(boots))
boots = make([]*upstream.UpstreamResolver, 0, len(addrs))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! The original code was using len(boots) as the capacity, which would always be 0 since the slice is being initialized. This would cause unnecessary reallocations during the append operations. Using len(addrs) is correct since that's the expected final size of the slice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant