Check if tag value is empty before allocation

closes #2390
closes #2404
This commit is contained in:
Leandro Piccilli
2017-02-14 00:56:48 +01:00
committed by Cameron Sparr
parent 54c9a385d5
commit 5da40d56ad
5 changed files with 34 additions and 7 deletions

View File

@@ -44,13 +44,18 @@ func New(
// pre-allocate exact size of the tags slice
taglen := 0
for k, v := range tags {
// TODO check that length of tag key & value are > 0
if len(k) == 0 || len(v) == 0 {
continue
}
taglen += 2 + len(escape(k, "tagkey")) + len(escape(v, "tagval"))
}
m.tags = make([]byte, taglen)
i := 0
for k, v := range tags {
if len(k) == 0 || len(v) == 0 {
continue
}
m.tags[i] = ','
i++
i += copy(m.tags[i:], escape(k, "tagkey"))