From 052beaa3ac519d4568a818d048aa6ca906418d33 Mon Sep 17 00:00:00 2001 From: Clayton O'Neill Date: Mon, 13 May 2019 11:18:27 -0400 Subject: [PATCH] Replace TrimPrefix w/special purpose implementation On the a-z benchmark, this brings the ns/op down from 5658 to 5533. Signed-off-by: Clayton O'Neill --- exporter.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/exporter.go b/exporter.go index d62a4bb..529df10 100644 --- a/exporter.go +++ b/exporter.go @@ -589,9 +589,18 @@ func parseDogStatsDTagsToLabels(component string) map[string]string { tagsReceived.Inc() tags := strings.Split(component, ",") for _, t := range tags { - t = strings.TrimPrefix(t, "#") - kv := strings.SplitN(t, ":", 2) + // Bail early if the tag is empty + if len(t) == 0 { + tagErrors.Inc() + log.Debugf("Empty tag found in '%s'", component) + continue + } + // Skip hash if found. + if t[0] == '#' { + t = t[1:] + } + kv := strings.SplitN(t, ":", 2) if len(kv) < 2 || len(kv[1]) == 0 { tagErrors.Inc() log.Debugf("Malformed or empty DogStatsD tag %s in component %s", t, component)