Skip to content

Commit c6fd368

Browse files
dev: preallocate some slices and maps (#2902)
1 parent a0b5b69 commit c6fd368

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pkg/config/linters_settings_gocritic.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func debugChecksListf(checks []string, format string, args ...interface{}) {
4747
}
4848

4949
func stringsSliceToSet(ss []string) map[string]bool {
50-
ret := map[string]bool{}
50+
ret := make(map[string]bool, len(ss))
5151
for _, s := range ss {
5252
ret[s] = true
5353
}
@@ -72,7 +72,7 @@ func gocriticCheckerTagsDebugf() {
7272

7373
tagToCheckers := buildGocriticTagToCheckersMap()
7474

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

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

119119
// EnabledTags
120120
if len(s.EnabledTags) != 0 {
@@ -192,7 +192,7 @@ func validateStringsUniq(ss []string) error {
192192
}
193193

194194
func intersectStringSlice(s1, s2 []string) []string {
195-
s1Map := make(map[string]struct{})
195+
s1Map := make(map[string]struct{}, len(s1))
196196
for _, s := range s1 {
197197
s1Map[s] = struct{}{}
198198
}
@@ -253,7 +253,7 @@ func (s *GocriticSettings) IsCheckEnabled(name string) bool {
253253
}
254254

255255
func sprintAllowedCheckerNames(allowedNames map[string]bool) string {
256-
var namesSlice []string
256+
namesSlice := make([]string, 0, len(allowedNames))
257257
for name := range allowedNames {
258258
namesSlice = append(namesSlice, name)
259259
}
@@ -267,7 +267,7 @@ func sprintStrings(ss []string) string {
267267

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

338338
func (s *GocriticSettings) GetLowercasedParams() map[string]GocriticCheckSettings {
339-
ret := map[string]GocriticCheckSettings{}
339+
ret := make(map[string]GocriticCheckSettings, len(s.SettingsPerCheck))
340340
for checker, params := range s.SettingsPerCheck {
341341
ret[strings.ToLower(checker)] = params
342342
}

0 commit comments

Comments
 (0)