File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 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) {
3939}
4040
4141func (tv * TagValue ) parse (rawFieldBytes []byte ) error {
42- sepIndex := bytes . IndexByte ( rawFieldBytes , '=' )
42+ var sepIndex int
4343
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 , '=' )
4464 switch sepIndex {
4565 case - 1 :
4666 return fmt .Errorf ("tagValue.Parse: No '=' in '%s'" , rawFieldBytes )
4767 case 0 :
4868 return fmt .Errorf ("tagValue.Parse: No tag in '%s'" , rawFieldBytes )
4969 }
5070
71+ PARSE:
5172 parsedTag , err := atoi (rawFieldBytes [:sepIndex ])
5273 if err != nil {
5374 return fmt .Errorf ("tagValue.Parse: %s" , err .Error ())
You can’t perform that action at this time.
0 commit comments