Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: preallocate some slices and maps #2902

Merged
merged 2 commits into from
Jun 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pkg/config/linters_settings_gocritic.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func debugChecksListf(checks []string, format string, args ...interface{}) {
}

func stringsSliceToSet(ss []string) map[string]bool {
ret := map[string]bool{}
ret := make(map[string]bool, len(ss))
for _, s := range ss {
ret[s] = true
}
Expand All @@ -72,7 +72,7 @@ func gocriticCheckerTagsDebugf() {

tagToCheckers := buildGocriticTagToCheckersMap()

var allTags []string
allTags := make([]string, 0, len(tagToCheckers))
for tag := range tagToCheckers {
allTags = append(allTags, tag)
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *GocriticSettings) InferEnabledChecks(log logutils.Log) {
disabledByDefaultChecks := getDefaultDisabledGocriticCheckersNames()
debugChecksListf(disabledByDefaultChecks, "Disabled by default")

var enabledChecks []string
enabledChecks := make([]string, 0, len(s.EnabledTags)+len(enabledByDefaultChecks))

// EnabledTags
if len(s.EnabledTags) != 0 {
Expand Down Expand Up @@ -192,7 +192,7 @@ func validateStringsUniq(ss []string) error {
}

func intersectStringSlice(s1, s2 []string) []string {
s1Map := make(map[string]struct{})
s1Map := make(map[string]struct{}, len(s1))
for _, s := range s1 {
s1Map[s] = struct{}{}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ func (s *GocriticSettings) IsCheckEnabled(name string) bool {
}

func sprintAllowedCheckerNames(allowedNames map[string]bool) string {
var namesSlice []string
namesSlice := make([]string, 0, len(allowedNames))
for name := range allowedNames {
namesSlice = append(namesSlice, name)
}
Expand All @@ -267,7 +267,7 @@ func sprintStrings(ss []string) string {

// getAllCheckerNames returns a map containing all checker names supported by gocritic.
func getAllCheckerNames() map[string]bool {
allCheckerNames := map[string]bool{}
allCheckerNames := make(map[string]bool, len(allGocriticCheckers))
for _, checker := range allGocriticCheckers {
allCheckerNames[strings.ToLower(checker.Name)] = true
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func (s *GocriticSettings) validateCheckerNames(log logutils.Log) error {
}

func (s *GocriticSettings) GetLowercasedParams() map[string]GocriticCheckSettings {
ret := map[string]GocriticCheckSettings{}
ret := make(map[string]GocriticCheckSettings, len(s.SettingsPerCheck))
for checker, params := range s.SettingsPerCheck {
ret[strings.ToLower(checker)] = params
}
Expand Down