perf: pre-allocate slices
Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
parent
c713bed4e3
commit
a49dee606b
|
@ -8,6 +8,7 @@ linters:
|
|||
- loggercheck
|
||||
- nilnil
|
||||
- nilerr
|
||||
- prealloc
|
||||
- revive
|
||||
- unconvert
|
||||
- unparam
|
||||
|
|
|
@ -163,11 +163,12 @@ func (c *Collectors) SetPerfCounterQuery() error {
|
|||
var (
|
||||
err error
|
||||
|
||||
perfCounterDependencies []string
|
||||
perfCounterNames []string
|
||||
perfIndicies []string
|
||||
perfCounterNames []string
|
||||
perfIndicies []string
|
||||
)
|
||||
|
||||
perfCounterDependencies := make([]string, 0, len(c.collectors))
|
||||
|
||||
for _, collector := range c.collectors {
|
||||
perfCounterNames, err = collector.GetPerfCounter()
|
||||
if err != nil {
|
||||
|
|
|
@ -130,8 +130,9 @@ func (c *collector) SetLogger(logger log.Logger) {
|
|||
|
||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
||||
// Perflib sources are dynamic, depending on the enabled child collectors
|
||||
var perflibDependencies []string
|
||||
for _, source := range utils.ExpandEnabledChildCollectors(*c.dfsrEnabledCollectors) {
|
||||
expandedChildCollectors := utils.ExpandEnabledChildCollectors(*c.dfsrEnabledCollectors)
|
||||
perflibDependencies := make([]string, 0, len(expandedChildCollectors))
|
||||
for _, source := range expandedChildCollectors {
|
||||
perflibDependencies = append(perflibDependencies, dfsrGetPerfObjectName(source))
|
||||
}
|
||||
|
||||
|
|
|
@ -373,7 +373,7 @@ func scrapeFile(path string, log log.Logger) ([]*dto.MetricFamily, error) {
|
|||
}
|
||||
|
||||
// Use temporary array to check for duplicates
|
||||
var families_array []*dto.MetricFamily
|
||||
families_array := make([]*dto.MetricFamily, 0, len(parsedFamilies))
|
||||
|
||||
for _, mf := range parsedFamilies {
|
||||
families_array = append(families_array, mf)
|
||||
|
|
Loading…
Reference in New Issue