Skip to content

Commit

Permalink
chore: fix linting issues and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
wI2L committed Oct 20, 2022
1 parent 55ad2c4 commit 60beb82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module github.com/wI2L/jsondiff

go 1.17

require github.com/tidwall/gjson v1.14.0
require github.com/tidwall/gjson v1.14.3

require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
)
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
github.com/tidwall/gjson v1.14.0 h1:6aeJ0bzojgWLa82gDQHcx3S0Lr/O51I9bJ5nv6JFx5w=
github.com/tidwall/gjson v1.14.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw=
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
24 changes: 15 additions & 9 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const (
)

const (
fromFieldLen = 10 // ,"from":""
valueFieldLen = 9 // ,"value":
opBaseLen = 19 // {"op":"","path":""}
fromFieldLen = len(`,"from":""`)
valueFieldLen = len(`,"value":`)
opBaseLen = len(`{"op":"","path":""}`)
)

// Patch represents a series of JSON Patch operations.
Expand Down Expand Up @@ -96,10 +96,13 @@ func (o Operation) hasValue() bool {
}

// String implements the fmt.Stringer interface.
func (p Patch) String() string {
func (p *Patch) String() string {
if p == nil {
return ""
}
sb := strings.Builder{}

for i, op := range p {
for i, op := range *p {
if i != 0 {
sb.WriteByte('\n')
}
Expand All @@ -122,15 +125,18 @@ func (p *Patch) append(typ string, from, path pointer, src, tgt interface{}) Pat
})
}

func (p Patch) jsonLength(targetBytes []byte) int {
func (p *Patch) jsonLength(targetBytes []byte) int {
length := 0
for _, op := range p {
if p == nil {
return length
}
for _, op := range *p {
length += op.jsonLength(targetBytes)
}
// Count comma-separators if the patch
// has more than one operation.
if len(p) > 1 {
length += len(p) - 1
if len(*p) > 1 {
length += len(*p) - 1
}
return length
}

0 comments on commit 60beb82

Please sign in to comment.