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
|
- loggercheck
|
||||||
- nilnil
|
- nilnil
|
||||||
- nilerr
|
- nilerr
|
||||||
|
- prealloc
|
||||||
- revive
|
- revive
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
|
|
|
@ -163,11 +163,12 @@ func (c *Collectors) SetPerfCounterQuery() error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
|
||||||
perfCounterDependencies []string
|
|
||||||
perfCounterNames []string
|
perfCounterNames []string
|
||||||
perfIndicies []string
|
perfIndicies []string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
perfCounterDependencies := make([]string, 0, len(c.collectors))
|
||||||
|
|
||||||
for _, collector := range c.collectors {
|
for _, collector := range c.collectors {
|
||||||
perfCounterNames, err = collector.GetPerfCounter()
|
perfCounterNames, err = collector.GetPerfCounter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -130,8 +130,9 @@ func (c *collector) SetLogger(logger log.Logger) {
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *collector) GetPerfCounter() ([]string, error) {
|
||||||
// Perflib sources are dynamic, depending on the enabled child collectors
|
// Perflib sources are dynamic, depending on the enabled child collectors
|
||||||
var perflibDependencies []string
|
expandedChildCollectors := utils.ExpandEnabledChildCollectors(*c.dfsrEnabledCollectors)
|
||||||
for _, source := range utils.ExpandEnabledChildCollectors(*c.dfsrEnabledCollectors) {
|
perflibDependencies := make([]string, 0, len(expandedChildCollectors))
|
||||||
|
for _, source := range expandedChildCollectors {
|
||||||
perflibDependencies = append(perflibDependencies, dfsrGetPerfObjectName(source))
|
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
|
// Use temporary array to check for duplicates
|
||||||
var families_array []*dto.MetricFamily
|
families_array := make([]*dto.MetricFamily, 0, len(parsedFamilies))
|
||||||
|
|
||||||
for _, mf := range parsedFamilies {
|
for _, mf := range parsedFamilies {
|
||||||
families_array = append(families_array, mf)
|
families_array = append(families_array, mf)
|
||||||
|
|
Loading…
Reference in New Issue