Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: optimize tag parsing by introducing cutTag helper function #67100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/encoding/json/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ type tagOptions string
// parseTag splits a struct field's json tag into its name and
// comma-separated options.
func parseTag(tag string) (string, tagOptions) {
tag, opt, _ := strings.Cut(tag, ",")
tag, opt := cutTag(tag)
return tag, tagOptions(opt)
}

func cutTag(tag string) (string, string) {
if i := strings.IndexByte(tag, ','); i >= 0 {
return tag[:i], tag[i+1:]
}
return tag, ""
}

// Contains reports whether a comma-separated list of options
// contains a particular substr flag. substr must be surrounded by a
// string boundary or commas.
Expand All @@ -29,7 +36,7 @@ func (o tagOptions) Contains(optionName string) bool {
s := string(o)
for s != "" {
var name string
name, s, _ = strings.Cut(s, ",")
name, s = cutTag(s)
if name == optionName {
return true
}
Expand Down