dev: preallocate some slices and maps (#2902)
This commit is contained in:
parent
a0b5b699f0
commit
c6fd368c89
@ -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
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
@ -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 {
|
||||
@ -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{}{}
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user