@@ -26,19 +26,46 @@ type Series struct {
26
26
}
27
27
28
28
func (s * Series ) SetTags () {
29
- tagSplits := strings .Split (s .Target , ";" )
29
+ numTags := strings .Count (s .Target , ";" )
30
+
31
+ if s .Tags == nil {
32
+ // +1 for the name tag
33
+ s .Tags = make (map [string ]string , numTags )
34
+ } else {
35
+ for k := range s .Tags {
36
+ delete (s .Tags , k )
37
+ }
38
+ }
39
+
40
+ if numTags == 0 {
41
+ s .Tags ["name" ] = s .Target
42
+ return
43
+ }
44
+
45
+ index := strings .IndexByte (s .Target , ';' )
46
+ name := s .Target [0 :index ]
30
47
31
- s .Tags = make (map [string ]string , len (tagSplits ))
48
+ remainder := s .Target
49
+ for index > 0 {
50
+ remainder = remainder [index + 1 :]
51
+ index = strings .IndexByte (remainder , ';' )
32
52
33
- for _ , tagPair := range tagSplits [1 :] {
34
- parts := strings .SplitN (tagPair , "=" , 2 )
35
- if len (parts ) != 2 {
53
+ tagPair := remainder
54
+ if index > 0 {
55
+ tagPair = remainder [:index ]
56
+ }
57
+
58
+ equalsPos := strings .IndexByte (tagPair , '=' )
59
+ if equalsPos < 1 {
36
60
// Shouldn't happen
37
61
continue
38
62
}
39
- s .Tags [parts [0 ]] = parts [1 ]
63
+
64
+ s .Tags [tagPair [0 :equalsPos ]] = tagPair [equalsPos + 1 :]
40
65
}
41
- s .Tags ["name" ] = tagSplits [0 ]
66
+
67
+ // Do this last to overwrite any invalid "name" tag that might be preset
68
+ s .Tags ["name" ] = name
42
69
}
43
70
44
71
func (s Series ) Copy (emptyDatapoints []schema.Point ) Series {
0 commit comments