@@ -559,7 +559,7 @@ func typeFields(t reflect.Type) structFields {
559
559
if tag == "-" {
560
560
continue
561
561
}
562
- name , opts := parseTag (tag )
562
+ name , opts , _ := strings . Cut (tag , "," )
563
563
if ! isValidTag (name ) {
564
564
name = ""
565
565
}
@@ -584,7 +584,7 @@ func typeFields(t reflect.Type) structFields {
584
584
tag : tagged ,
585
585
index : index ,
586
586
typ : ft ,
587
- omitEmpty : opts .Contains ("omitempty" ),
587
+ omitEmpty : tagOptions ( opts ) .Contains ("omitempty" ),
588
588
}
589
589
field .nameBytes = []byte (field .name )
590
590
field .equalFold = foldFunc (field .nameBytes )
@@ -698,15 +698,6 @@ func cachedTypeFields(t reflect.Type) structFields {
698
698
// tag, or the empty string. It does not include the leading comma.
699
699
type tagOptions string
700
700
701
- // parseTag splits a struct field's json tag into its name and
702
- // comma-separated options.
703
- func parseTag (tag string ) (string , tagOptions ) {
704
- if idx := strings .Index (tag , "," ); idx != - 1 {
705
- return tag [:idx ], tagOptions (tag [idx + 1 :])
706
- }
707
- return tag , tagOptions ("" )
708
- }
709
-
710
701
// Contains reports whether a comma-separated list of options
711
702
// contains a particular substr flag. substr must be surrounded by a
712
703
// string boundary or commas.
@@ -717,10 +708,7 @@ func (o tagOptions) Contains(optionName string) bool {
717
708
s := string (o )
718
709
for s != "" {
719
710
var next string
720
- i := strings .Index (s , "," )
721
- if i >= 0 {
722
- s , next = s [:i ], s [i + 1 :]
723
- }
711
+ s , next , _ = strings .Cut (s , "," )
724
712
if s == optionName {
725
713
return true
726
714
}
0 commit comments