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

perf: use strings.Builder in GoString #111

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
19 changes: 13 additions & 6 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,23 @@ func (ve *ValidationError) Error() string {
return fmt.Sprintf("jsonschema: %s does not validate with %s: %s", quote(leaf.InstanceLocation), u+"#"+leaf.KeywordLocation, leaf.Message)
}

func (ve *ValidationError) GoString() string {
func (ve *ValidationError) goStringTo(tgt *strings.Builder, indent int) {
sloc := ve.AbsoluteKeywordLocation
sloc = sloc[strings.IndexByte(sloc, '#')+1:]
msg := fmt.Sprintf("[I#%s] [S#%s] %s", ve.InstanceLocation, sloc, ve.Message)
for i := 0; i < indent; i++ {
tgt.WriteByte(' ')
}
tgt.WriteString(fmt.Sprintf("[I#%s] [S#%s] %s", ve.InstanceLocation, sloc, ve.Message))
for _, c := range ve.Causes {
for _, line := range strings.Split(c.GoString(), "\n") {
msg += "\n " + line
}
tgt.WriteByte('\n')
c.goStringTo(tgt, indent+2)
zedongh marked this conversation as resolved.
Show resolved Hide resolved
}
return msg
}

func (ve *ValidationError) GoString() string {
var msgBuf strings.Builder
ve.goStringTo(&msgBuf, 0)
return msgBuf.String()
}

func joinPtr(ptr1, ptr2 string) string {
Expand Down