Skip to content

Commit b2c438f

Browse files
committed
Using ifs instead of switch for speed
1 parent 7b96513 commit b2c438f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

parser.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ func nextValue(data []byte) int {
2323
// Tries to find the end of string
2424
// Support if string contains escaped quote symbols.
2525
func stringEnd(data []byte) int {
26-
escaped := false
2726
for i, c := range data {
28-
switch c {
29-
case '\\':
30-
escaped = !escaped
31-
case '"':
32-
if !escaped {
33-
return i + 1
27+
if c == '"' {
28+
j := i - 1
29+
for {
30+
if j < 0 || data[j] != '\\' {
31+
return i + 1 // even number of backslashes
32+
}
33+
j--
34+
if j < 0 || data[j] != '\\' {
35+
break // odd number of backslashes
36+
}
37+
j--
3438
}
35-
escaped = false
36-
default:
37-
escaped = false
3839
}
3940
}
4041

0 commit comments

Comments
 (0)