Skip to content

Commit

Permalink
perf(location): do not make a copy of data
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Nov 3, 2022
1 parent d8622f7 commit 4355753
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 2 additions & 0 deletions internal/location/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func (f File) IsZero() bool {
}

// NewFile creates a new File.
//
// Do not modify the data after calling this function, Lines will point to it.
func NewFile(name, source string, data []byte) File {
f := File{
Name: name,
Expand Down
4 changes: 1 addition & 3 deletions internal/location/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package location

import (
"bytes"

"golang.org/x/exp/slices"
)

// Lines is a sorted slice of newline offsets.
Expand Down Expand Up @@ -51,7 +49,7 @@ func (l Lines) Line(n int) (start, end int) {

// Collect fills the given slice with the offset of newlines.
func (l *Lines) Collect(data []byte) {
l.data = slices.Clone(data)
l.data = data
l.lines = l.lines[:0]

var (
Expand Down
2 changes: 1 addition & 1 deletion jsonschema/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p *Parser) getResolver(loc string) (r resolver, rerr error) {

r = resolver{
ReferenceResolver: NewRootResolver(&node),
file: location.NewFile(loc, loc, raw),
file: file,
}
p.schemas[loc] = r

Expand Down

0 comments on commit 4355753

Please sign in to comment.