File tree 1 file changed +22
-1
lines changed
1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -39,15 +39,36 @@ func (tv *TagValue) init(tag Tag, value []byte) {
39
39
}
40
40
41
41
func (tv * TagValue ) parse (rawFieldBytes []byte ) error {
42
- sepIndex := bytes . IndexByte ( rawFieldBytes , '=' )
42
+ var sepIndex int
43
43
44
+ // Most of the Fix tags are 4 or less characters long, so we can optimize
45
+ // for that by checking the 5 first characters without looping over the
46
+ // whole byte slice.
47
+ if len (rawFieldBytes ) >= 5 {
48
+ if rawFieldBytes [1 ] == '=' {
49
+ sepIndex = 1
50
+ goto PARSE
51
+ } else if rawFieldBytes [2 ] == '=' {
52
+ sepIndex = 2
53
+ goto PARSE
54
+ } else if rawFieldBytes [3 ] == '=' {
55
+ sepIndex = 3
56
+ goto PARSE
57
+ } else if rawFieldBytes [4 ] == '=' {
58
+ sepIndex = 4
59
+ goto PARSE
60
+ }
61
+ }
62
+
63
+ sepIndex = bytes .IndexByte (rawFieldBytes , '=' )
44
64
switch sepIndex {
45
65
case - 1 :
46
66
return fmt .Errorf ("tagValue.Parse: No '=' in '%s'" , rawFieldBytes )
47
67
case 0 :
48
68
return fmt .Errorf ("tagValue.Parse: No tag in '%s'" , rawFieldBytes )
49
69
}
50
70
71
+ PARSE:
51
72
parsedTag , err := atoi (rawFieldBytes [:sepIndex ])
52
73
if err != nil {
53
74
return fmt .Errorf ("tagValue.Parse: %s" , err .Error ())
You can’t perform that action at this time.
0 commit comments