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 <claytono@github.com>
This commit is contained in:
Clayton O'Neill 2019-05-13 11:18:27 -04:00
parent 9cd711ed3e
commit 052beaa3ac
No known key found for this signature in database
GPG key ID: 5017D45C788B5274

View file

@ -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)