Skip to content

Commit

Permalink
fix(parser): reduce complexity of initializeJSONLine
Browse files Browse the repository at this point in the history
  • Loading branch information
i.merzlyakov committed Dec 4, 2023
1 parent 66cbf9c commit f271be4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/parser/json/json_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func initializeJSONLine(doc []byte) *jsonLine {
parent: "",
}

line := 1
prevInputOffset := 0

// for each token inside JSON
for {
tok, err := dec.Token()
Expand Down Expand Up @@ -80,15 +83,14 @@ func initializeJSONLine(doc []byte) *jsonLine {
continue
}

line := 1
// get the correct line based on byte offset
for i, val := range doc {
if i == int(dec.InputOffset()) {
break
} else if val == byte('\n') {
currentInputOffset := int(dec.InputOffset())
for i := prevInputOffset; i < currentInputOffset; i++ {
if doc[i] == byte('\n') {
line++
}
}
prevInputOffset = currentInputOffset

// insert into line information map
if _, ok := newMap[tokStringRepresentation]; !ok {
Expand Down

0 comments on commit f271be4

Please sign in to comment.